aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-08-25 10:04:38 -0700
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-08-25 10:04:58 -0700
commitb17e4e88f6f09a578be22d5a39cb47c8f14422ed (patch)
tree628f7a3740313006cea1a6c8c803bd2d5942dadb
parentc327833314fafd4accb9bbfbaf01f0dbee7a9a10 (diff)
Expose real error messages for internal server API errors
-rw-r--r--api/category.go8
-rw-r--r--api/entry.go16
-rw-r--r--api/feed.go14
-rw-r--r--api/icon.go2
-rw-r--r--api/subscription.go3
-rw-r--r--api/user.go8
6 files changed, 25 insertions, 26 deletions
diff --git a/api/category.go b/api/category.go
index 86766c9..5a57865 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 cb9c043..37917c7 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 0474005..a295451 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 2d2171a..0ad1081 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 ee471c6..603b932 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 1222ccd..5ad056e 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
}