Browse Source

Fix error handling and logging issue after refactoring

Frédéric Guillot 2 years ago
parent
commit
500c60b807

+ 2 - 2
internal/cli/refresh_feeds.go

@@ -56,11 +56,11 @@ func refreshFeeds(store *storage.Storage) {
 					slog.Int("worker_id", workerID),
 				)
 
-				if err := feedHandler.RefreshFeed(store, job.UserID, job.FeedID, false); err != nil {
+				if localizedError := feedHandler.RefreshFeed(store, job.UserID, job.FeedID, false); err != nil {
 					slog.Warn("Unable to refresh feed",
 						slog.Int64("feed_id", job.FeedID),
 						slog.Int64("user_id", job.UserID),
-						slog.Any("error", err),
+						slog.Any("error", localizedError.Error()),
 					)
 				}
 			}

+ 1 - 1
internal/locale/translations/de_DE.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/el_EL.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/en_US.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/es_ES.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/fi_FI.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/fr_FR.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "Vous avez déclenché trop d'actualisations de flux. Veuillez attendre 30 minutes avant de réessayer.",
     "alert.background_feed_refresh": "Les abonnements sont en cours d'actualisation en arrière-plan. Vous pouvez continuer à naviguer dans l'application.",
     "error.http_response_too_large": "La réponse HTTP est trop volumineuse. Vous pouvez augmenter la limite de taille de réponse HTTP dans les paramètres de l'application (redémarrage de l'application nécessaire).",
-    "error.http_body_read": "Impossible de lire le corps de la réponse HTTP.",
+    "error.http_body_read": "Impossible de lire le corps de la réponse HTTP : %v.",
     "error.http_empty_response_body": "Le corps de la réponse HTTP est vide.",
     "error.http_empty_response": "La réponse HTTP est vide. Peut-être que ce site web bloque Miniflux avec une protection anti-bot ?",
     "error.tls_error": "Erreur TLS : %v. Vous pouvez désactiver la vérification TLS dans les paramètres de l'abonnement.",

+ 1 - 1
internal/locale/translations/hi_IN.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/id_ID.json

@@ -430,7 +430,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/it_IT.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/ja_JP.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/nl_NL.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/pl_PL.json

@@ -447,7 +447,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/pt_BR.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/ru_RU.json

@@ -447,7 +447,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/tr_TR.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/uk_UA.json

@@ -448,7 +448,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/zh_CN.json

@@ -431,7 +431,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 1 - 1
internal/locale/translations/zh_TW.json

@@ -439,7 +439,7 @@
     "alert.too_many_feeds_refresh": "You have triggered too many feed refreshes. Please wait 30 minutes before trying again.",
     "alert.background_feed_refresh": "All feeds are being refreshed in the background. You can continue to use Miniflux while this process is running.",
     "error.http_response_too_large": "The HTTP response is too large. You could increase the HTTP response size limit in the global settings (requires a server restart).",
-    "error.http_body_read": "Unable to read the HTTP body.",
+    "error.http_body_read": "Unable to read the HTTP body: %v.",
     "error.http_empty_response_body": "The HTTP response body is empty.",
     "error.http_empty_response": "The HTTP response is empty. Perhaps, this website is using a bot protection mechanism?",
     "error.tls_error": "TLS error: %v. You could disable TLS verification in the feed settings if you would like.",

+ 2 - 2
internal/reader/fetcher/response_handler.go

@@ -78,8 +78,8 @@ func (r *ResponseHandler) ReadBody(maxBodySize int64) ([]byte, *locale.Localized
 
 	buffer, err := io.ReadAll(limitedReader)
 	if err != nil && err != io.EOF {
-		if err == io.ErrUnexpectedEOF {
-			return nil, locale.NewLocalizedErrorWrapper(fmt.Errorf("fetcher: response body too large: %w", err), "error.http_response_too_large")
+		if err, ok := err.(*http.MaxBytesError); ok {
+			return nil, locale.NewLocalizedErrorWrapper(fmt.Errorf("fetcher: response body too large: %d bytes", err.Limit), "error.http_response_too_large")
 		}
 
 		return nil, locale.NewLocalizedErrorWrapper(fmt.Errorf("fetcher: unable to read response body: %w", err), "error.http_body_read", err)

+ 2 - 2
internal/ui/feed_refresh.go

@@ -19,12 +19,12 @@ import (
 func (h *handler) refreshFeed(w http.ResponseWriter, r *http.Request) {
 	feedID := request.RouteInt64Param(r, "feedID")
 	forceRefresh := request.QueryBoolParam(r, "forceRefresh", false)
-	if err := feedHandler.RefreshFeed(h.store, request.UserID(r), feedID, forceRefresh); err != nil {
+	if localizedError := feedHandler.RefreshFeed(h.store, request.UserID(r), feedID, forceRefresh); localizedError != nil {
 		slog.Warn("Unable to refresh feed",
 			slog.Int64("user_id", request.UserID(r)),
 			slog.Int64("feed_id", feedID),
 			slog.Bool("force_refresh", forceRefresh),
-			slog.Any("error", err),
+			slog.Any("error", localizedError.Error()),
 		)
 	}