diff options
author | Frédéric Guillot <fred@miniflux.net> | 2018-06-30 12:42:12 -0700 |
---|---|---|
committer | Frédéric Guillot <fred@miniflux.net> | 2018-06-30 12:42:12 -0700 |
commit | 9c0f882ba0c7f8635ff7ab8007d134f7aefd69f2 (patch) | |
tree | 4056c457596aa471adcdf32cc712ca51d83eae02 /reader | |
parent | a40f592aab89cc6e5c8f2a9be8ed912f8204f070 (diff) |
Add specific 404 and 401 error messages
Diffstat (limited to 'reader')
-rw-r--r-- | reader/feed/handler.go | 11 | ||||
-rw-r--r-- | reader/subscription/finder.go | 10 |
2 files changed, 20 insertions, 1 deletions
diff --git a/reader/feed/handler.go b/reader/feed/handler.go index 24fdadf..f01b877 100644 --- a/reader/feed/handler.go +++ b/reader/feed/handler.go @@ -21,12 +21,13 @@ import ( var ( errRequestFailed = "Unable to execute request: %v" - errServerFailure = "Unable to fetch feed (statusCode=%d)" + errServerFailure = "Unable to fetch feed (Status Code = %d)" errDuplicate = "This feed already exists (%s)" errNotFound = "Feed %d not found" errEncoding = "Unable to normalize encoding: %q" errCategoryNotFound = "Category not found for this user" errEmptyFeed = "This feed is empty" + errResourceNotFound = "Resource not found (404), this feed doesn't exists anymore, check the feed URL" ) // Handler contains all the logic to create and refresh feeds. @@ -152,6 +153,14 @@ func (h *Handler) RefreshFeed(userID, feedID int64) error { originalFeed.CheckedAt = time.Now() + if response.IsNotFound() { + err := errors.NewLocalizedError(errResourceNotFound) + originalFeed.ParsingErrorCount++ + originalFeed.ParsingErrorMsg = err.Localize(currentLanguage) + h.store.UpdateFeed(originalFeed) + return err + } + if response.HasServerFailure() { err := errors.NewLocalizedError(errServerFailure, response.StatusCode) originalFeed.ParsingErrorCount++ diff --git a/reader/subscription/finder.go b/reader/subscription/finder.go index 6b45cfb..57fbd11 100644 --- a/reader/subscription/finder.go +++ b/reader/subscription/finder.go @@ -24,6 +24,8 @@ var ( errConnectionFailure = "Unable to open this link: %v" errUnreadableDoc = "Unable to analyze this page: %v" errEmptyBody = "This web page is empty" + errNotAuthorized = "You are not authorized to access this resource (invalid username/password)" + errServerFailure = "Unable to fetch this resource (Status Code = %d)" ) // FindSubscriptions downloads and try to find one or more subscriptions from an URL. @@ -40,6 +42,14 @@ func FindSubscriptions(websiteURL, username, password string) (Subscriptions, er return nil, errors.NewLocalizedError(errConnectionFailure, err) } + if response.IsNotAuthorized() { + return nil, errors.NewLocalizedError(errNotAuthorized) + } + + if response.HasServerFailure() { + return nil, errors.NewLocalizedError(errServerFailure, response.StatusCode) + } + // Content-Length = -1 when no Content-Length header is sent if response.ContentLength == 0 { return nil, errors.NewLocalizedError(errEmptyBody) |