Просмотр исходного кода

Add specific 404 and 401 error messages

Frédéric Guillot 7 лет назад
Родитель
Сommit
9c0f882ba0

+ 10 - 0
http/client/response.go

@@ -24,6 +24,16 @@ type Response struct {
 	ContentLength int64
 }
 
+// IsNotFound returns true if the resource doesn't exists anymore.
+func (r *Response) IsNotFound() bool {
+	return r.StatusCode == 404 || r.StatusCode == 410
+}
+
+// IsNotAuthorized returns true if the resource require authentication.
+func (r *Response) IsNotAuthorized() bool {
+	return r.StatusCode == 401
+}
+
 // HasServerFailure returns true if the status code represents a failure.
 func (r *Response) HasServerFailure() bool {
 	return r.StatusCode >= 400

+ 15 - 12
locale/translations.go

@@ -1,5 +1,5 @@
 // Code generated by go generate; DO NOT EDIT.
-// 2018-06-20 09:43:57.979429995 +0200 CEST m=+0.030917486
+// 2018-06-30 12:36:10.057382143 -0700 PDT m=+0.028630754
 
 package locale
 
@@ -91,7 +91,7 @@ var translations = map[string]string{
     "Yes": "Ja",
     "No": "Nein",
     "This feed already exists (%s)": "Diese Abonnement existiert bereits (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Abonnement konnte nicht abgerufen werden (code=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Abonnement konnte nicht abgerufen werden (code=%d)",
     "Unable to open this link: %v": "Dieser Link konnte nicht geöffnet werden: %v",
     "Unable to analyze this page: %v": "Diese Seite konnte nicht analysiert werden: %v",
     "Unable to find any subscription.": "Es wurden keine Abonnements gefunden.",
@@ -338,7 +338,7 @@ var translations = map[string]string{
     "Yes": "Oui",
     "No": "Non",
     "This feed already exists (%s)": "Cet abonnement existe déjà (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Impossible de récupérer cet abonnement (code=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Impossible de récupérer cet abonnement (code=%d)",
     "Unable to open this link: %v": "Impossible d'ouvrir ce lien : %v",
     "Unable to analyze this page: %v": "Impossible d'analyzer cette page : %v",
     "Unable to find any subscription.": "Impossible de trouver un abonnement.",
@@ -485,7 +485,10 @@ var translations = map[string]string{
     "Unable to fetch request token from Pocket!": "Impossible de récupérer le jeton d'accès depuis Pocket !",
     "Advanced Options": "Options avancées",
     "Feed Username": "Nom d'utilisateur du flux",
-    "Feed Password": "Mot de passe du flux"
+    "Feed Password": "Mot de passe du flux",
+    "You are not authorized to access this resource (invalid username/password)": "Vous n'êtes pas autorisé à accéder à cette ressource (nom d'utilisateur / mot de passe incorrect)",
+    "Unable to fetch this resource (Status Code = %d)": "Impossible de récupérer cette ressource (code=%d)",
+    "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux"
 }
 `,
 	"nl_NL": `{
@@ -574,7 +577,7 @@ var translations = map[string]string{
     "Yes": "Ja",
     "No": "Nee",
     "This feed already exists (%s)": "Deze feed bestaat al (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Kon feed niet update (code=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Kon feed niet update (code=%d)",
     "Unable to open this link: %v": "Kon link niet volgen: %v",
     "Unable to analyze this page: %v": "Kon pagina niet analyseren: %v",
     "Unable to find any subscription.": "Kon geen feeds vinden.",
@@ -798,7 +801,7 @@ var translations = map[string]string{
     "Yes": "Tak",
     "No": "Nie",
     "This feed already exists (%s)": "Ten kanał już istnieje (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Kanał nie mógł zostać pobrany (kod=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Kanał nie mógł zostać pobrany (kod=%d)",
     "Unable to open this link: %v": "Nie można było otworzyć tego linku: %v",
     "Unable to analyze this page: %v": "Nie można przeanalizować tej strony: %v",
     "Unable to find any subscription.": "Nie znaleziono żadnych subskrypcji.",
@@ -1020,7 +1023,7 @@ var translations = map[string]string{
     "Yes": "是",
     "No": "否",
     "This feed already exists (%s)": "源已存在 (%s)",
-    "Unable to fetch feed (statusCode=%d)": "无法获取源 (错误代码=%d)",
+    "Unable to fetch feed (Status Code = %d)": "无法获取源 (错误代码=%d)",
     "Unable to open this link: %v": "无法打开这一链接: %v",
     "Unable to analyze this page: %v": "无法分析这一页面: %v",
     "Unable to find any subscription.": "找不到任何订阅.",
@@ -1158,10 +1161,10 @@ var translations = map[string]string{
 }
 
 var translationsChecksums = map[string]string{
-	"de_DE": "120f472a466191939ea8d72c469f9703720cec24a28a3f79d400d5501820a8ce",
+	"de_DE": "bbc822f9acd0033eca10ac025229d375c9509977d5ba47afacbfb5b597bbc24c",
 	"en_US": "6fe95384260941e8a5a3c695a655a932e0a8a6a572c1e45cb2b1ae8baa01b897",
-	"fr_FR": "734b9ee6edc65e5c076fc91999d81f6c586eeb52f420101049bff9b501cbae54",
-	"nl_NL": "1a73f1dd1c4c0d2c2adc8695cdd050c2dad81c14876caed3892b44adc2491265",
-	"pl_PL": "da709c14ff71f3b516eec66cb2758d89c5feab1472c94b2b518f425162a9f806",
-	"zh_CN": "d80594c1b67d15e9f4673d3d62fe4949e8606a5fdfb741d8a8921f21dceb8cf2",
+	"fr_FR": "7a451a1d09e051a847f554937e07a6af24b92f1da7f46da8c0ef2d4cc31bcec6",
+	"nl_NL": "bec647fdfb325a30050c50bdb9a29fee58b0705109d32c09b5ace77aa0777e7c",
+	"pl_PL": "2295f35a98c8f60cfc6bab241d26b224c06979cc9ca3740bb89c63c7596a0431",
+	"zh_CN": "f5fb0a9b7336c51e74d727a2fb294bab3514e3002376da7fd904e0d7caed1a1c",
 }

+ 1 - 1
locale/translations/de_DE.json

@@ -85,7 +85,7 @@
     "Yes": "Ja",
     "No": "Nein",
     "This feed already exists (%s)": "Diese Abonnement existiert bereits (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Abonnement konnte nicht abgerufen werden (code=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Abonnement konnte nicht abgerufen werden (code=%d)",
     "Unable to open this link: %v": "Dieser Link konnte nicht geöffnet werden: %v",
     "Unable to analyze this page: %v": "Diese Seite konnte nicht analysiert werden: %v",
     "Unable to find any subscription.": "Es wurden keine Abonnements gefunden.",

+ 5 - 2
locale/translations/fr_FR.json

@@ -85,7 +85,7 @@
     "Yes": "Oui",
     "No": "Non",
     "This feed already exists (%s)": "Cet abonnement existe déjà (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Impossible de récupérer cet abonnement (code=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Impossible de récupérer cet abonnement (code=%d)",
     "Unable to open this link: %v": "Impossible d'ouvrir ce lien : %v",
     "Unable to analyze this page: %v": "Impossible d'analyzer cette page : %v",
     "Unable to find any subscription.": "Impossible de trouver un abonnement.",
@@ -232,5 +232,8 @@
     "Unable to fetch request token from Pocket!": "Impossible de récupérer le jeton d'accès depuis Pocket !",
     "Advanced Options": "Options avancées",
     "Feed Username": "Nom d'utilisateur du flux",
-    "Feed Password": "Mot de passe du flux"
+    "Feed Password": "Mot de passe du flux",
+    "You are not authorized to access this resource (invalid username/password)": "Vous n'êtes pas autorisé à accéder à cette ressource (nom d'utilisateur / mot de passe incorrect)",
+    "Unable to fetch this resource (Status Code = %d)": "Impossible de récupérer cette ressource (code=%d)",
+    "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux"
 }

+ 1 - 1
locale/translations/nl_NL.json

@@ -84,7 +84,7 @@
     "Yes": "Ja",
     "No": "Nee",
     "This feed already exists (%s)": "Deze feed bestaat al (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Kon feed niet update (code=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Kon feed niet update (code=%d)",
     "Unable to open this link: %v": "Kon link niet volgen: %v",
     "Unable to analyze this page: %v": "Kon pagina niet analyseren: %v",
     "Unable to find any subscription.": "Kon geen feeds vinden.",

+ 1 - 1
locale/translations/pl_PL.json

@@ -87,7 +87,7 @@
     "Yes": "Tak",
     "No": "Nie",
     "This feed already exists (%s)": "Ten kanał już istnieje (%s)",
-    "Unable to fetch feed (statusCode=%d)": "Kanał nie mógł zostać pobrany (kod=%d)",
+    "Unable to fetch feed (Status Code = %d)": "Kanał nie mógł zostać pobrany (kod=%d)",
     "Unable to open this link: %v": "Nie można było otworzyć tego linku: %v",
     "Unable to analyze this page: %v": "Nie można przeanalizować tej strony: %v",
     "Unable to find any subscription.": "Nie znaleziono żadnych subskrypcji.",

+ 1 - 1
locale/translations/zh_CN.json

@@ -85,7 +85,7 @@
     "Yes": "是",
     "No": "否",
     "This feed already exists (%s)": "源已存在 (%s)",
-    "Unable to fetch feed (statusCode=%d)": "无法获取源 (错误代码=%d)",
+    "Unable to fetch feed (Status Code = %d)": "无法获取源 (错误代码=%d)",
     "Unable to open this link: %v": "无法打开这一链接: %v",
     "Unable to analyze this page: %v": "无法分析这一页面: %v",
     "Unable to find any subscription.": "找不到任何订阅.",

+ 10 - 1
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++

+ 10 - 0
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)