From b17e4e88f6f09a578be22d5a39cb47c8f14422ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 25 Aug 2018 10:04:38 -0700 Subject: [PATCH] Expose real error messages for internal server API errors --- api/category.go | 8 ++++---- api/entry.go | 16 ++++++++-------- api/feed.go | 14 +++++++------- api/icon.go | 2 +- api/subscription.go | 3 +-- api/user.go | 8 ++++---- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/api/category.go b/api/category.go index 86766c91..5a578652 100644 --- a/api/category.go +++ b/api/category.go @@ -36,7 +36,7 @@ func (c *Controller) CreateCategory(w http.ResponseWriter, r *http.Request) { err = c.store.CreateCategory(category) if err != nil { - json.ServerError(w, errors.New("Unable to create this category")) + json.ServerError(w, err) return } @@ -67,7 +67,7 @@ func (c *Controller) UpdateCategory(w http.ResponseWriter, r *http.Request) { err = c.store.UpdateCategory(category) if err != nil { - json.ServerError(w, errors.New("Unable to update this category")) + json.ServerError(w, err) return } @@ -79,7 +79,7 @@ func (c *Controller) GetCategories(w http.ResponseWriter, r *http.Request) { ctx := context.New(r) categories, err := c.store.Categories(ctx.UserID()) if err != nil { - json.ServerError(w, errors.New("Unable to fetch categories")) + json.ServerError(w, err) return } @@ -102,7 +102,7 @@ func (c *Controller) RemoveCategory(w http.ResponseWriter, r *http.Request) { } if err := c.store.RemoveCategory(userID, categoryID); err != nil { - json.ServerError(w, errors.New("Unable to remove this category")) + json.ServerError(w, err) return } diff --git a/api/entry.go b/api/entry.go index cb9c0435..37917c78 100644 --- a/api/entry.go +++ b/api/entry.go @@ -39,7 +39,7 @@ func (c *Controller) GetFeedEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - json.ServerError(w, errors.New("Unable to fetch this entry from the database")) + json.ServerError(w, err) return } @@ -64,7 +64,7 @@ func (c *Controller) GetEntry(w http.ResponseWriter, r *http.Request) { entry, err := builder.GetEntry() if err != nil { - json.ServerError(w, errors.New("Unable to fetch this entry from the database")) + json.ServerError(w, err) return } @@ -122,13 +122,13 @@ func (c *Controller) GetFeedEntries(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - json.ServerError(w, errors.New("Unable to fetch the list of entries")) + json.ServerError(w, err) return } count, err := builder.CountEntries() if err != nil { - json.ServerError(w, errors.New("Unable to count the number of entries")) + json.ServerError(w, err) return } @@ -174,13 +174,13 @@ func (c *Controller) GetEntries(w http.ResponseWriter, r *http.Request) { entries, err := builder.GetEntries() if err != nil { - json.ServerError(w, errors.New("Unable to fetch the list of entries")) + json.ServerError(w, err) return } count, err := builder.CountEntries() if err != nil { - json.ServerError(w, errors.New("Unable to count the number of entries")) + json.ServerError(w, err) return } @@ -201,7 +201,7 @@ func (c *Controller) SetEntryStatus(w http.ResponseWriter, r *http.Request) { } if err := c.store.SetEntriesStatus(context.New(r).UserID(), entryIDs, status); err != nil { - json.ServerError(w, errors.New("Unable to change entries status")) + json.ServerError(w, err) return } @@ -217,7 +217,7 @@ func (c *Controller) ToggleBookmark(w http.ResponseWriter, r *http.Request) { } if err := c.store.ToggleBookmark(context.New(r).UserID(), entryID); err != nil { - json.ServerError(w, errors.New("Unable to toggle bookmark value")) + json.ServerError(w, err) return } diff --git a/api/feed.go b/api/feed.go index 04740052..a295451b 100644 --- a/api/feed.go +++ b/api/feed.go @@ -53,7 +53,7 @@ func (c *Controller) CreateFeed(w http.ResponseWriter, r *http.Request) { feedInfo.Password, ) if err != nil { - json.ServerError(w, errors.New("Unable to create this feed")) + json.ServerError(w, err) return } @@ -82,7 +82,7 @@ func (c *Controller) RefreshFeed(w http.ResponseWriter, r *http.Request) { err = c.feedHandler.RefreshFeed(userID, feedID) if err != nil { - json.ServerError(w, errors.New("Unable to refresh this feed")) + json.ServerError(w, err) return } @@ -125,13 +125,13 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) { } if err := c.store.UpdateFeed(originalFeed); err != nil { - json.ServerError(w, errors.New("Unable to update this feed")) + json.ServerError(w, err) return } originalFeed, err = c.store.FeedByID(userID, feedID) if err != nil { - json.ServerError(w, errors.New("Unable to fetch this feed")) + json.ServerError(w, err) return } @@ -142,7 +142,7 @@ func (c *Controller) UpdateFeed(w http.ResponseWriter, r *http.Request) { func (c *Controller) GetFeeds(w http.ResponseWriter, r *http.Request) { feeds, err := c.store.Feeds(context.New(r).UserID()) if err != nil { - json.ServerError(w, errors.New("Unable to fetch feeds from the database")) + json.ServerError(w, err) return } @@ -159,7 +159,7 @@ func (c *Controller) GetFeed(w http.ResponseWriter, r *http.Request) { feed, err := c.store.FeedByID(context.New(r).UserID(), feedID) if err != nil { - json.ServerError(w, errors.New("Unable to fetch this feed")) + json.ServerError(w, err) return } @@ -188,7 +188,7 @@ func (c *Controller) RemoveFeed(w http.ResponseWriter, r *http.Request) { } if err := c.store.RemoveFeed(userID, feedID); err != nil { - json.ServerError(w, errors.New("Unable to remove this feed")) + json.ServerError(w, err) return } diff --git a/api/icon.go b/api/icon.go index 2d2171a8..0ad1081c 100644 --- a/api/icon.go +++ b/api/icon.go @@ -28,7 +28,7 @@ func (c *Controller) FeedIcon(w http.ResponseWriter, r *http.Request) { icon, err := c.store.IconByFeedID(context.New(r).UserID(), feedID) if err != nil { - json.ServerError(w, errors.New("Unable to fetch feed icon")) + json.ServerError(w, err) return } diff --git a/api/subscription.go b/api/subscription.go index ee471c6b..603b9321 100644 --- a/api/subscription.go +++ b/api/subscription.go @@ -5,7 +5,6 @@ package api // import "miniflux.app/api" import ( - "errors" "fmt" "net/http" @@ -27,7 +26,7 @@ func (c *Controller) GetSubscriptions(w http.ResponseWriter, r *http.Request) { subscriptionInfo.Password, ) if err != nil { - json.ServerError(w, errors.New("Unable to discover subscriptions")) + json.ServerError(w, err) return } diff --git a/api/user.go b/api/user.go index 1222ccdf..5ad056ea 100644 --- a/api/user.go +++ b/api/user.go @@ -51,7 +51,7 @@ func (c *Controller) CreateUser(w http.ResponseWriter, r *http.Request) { err = c.store.CreateUser(user) if err != nil { - json.ServerError(w, errors.New("Unable to create this user")) + json.ServerError(w, err) return } @@ -97,7 +97,7 @@ func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request) { } if err = c.store.UpdateUser(originalUser); err != nil { - json.ServerError(w, errors.New("Unable to update this user")) + json.ServerError(w, err) return } @@ -114,7 +114,7 @@ func (c *Controller) Users(w http.ResponseWriter, r *http.Request) { users, err := c.store.Users() if err != nil { - json.ServerError(w, errors.New("Unable to fetch the list of users")) + json.ServerError(w, err) return } @@ -190,7 +190,7 @@ func (c *Controller) RemoveUser(w http.ResponseWriter, r *http.Request) { user, err := c.store.UserByID(userID) if err != nil { - json.ServerError(w, errors.New("Unable to fetch this user from the database")) + json.ServerError(w, err) return }