Expose real error messages for internal server API errors
This commit is contained in:
parent
c327833314
commit
b17e4e88f6
6 changed files with 25 additions and 26 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
16
api/entry.go
16
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
|
||||
}
|
||||
|
||||
|
|
14
api/feed.go
14
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue