diff options
author | 2023-10-21 19:50:29 -0700 | |
---|---|---|
committer | 2023-10-22 13:09:30 -0700 | |
commit | 14e25ab9fe09b9951b38e56af2bdff7a0737b280 (patch) | |
tree | 1e466305ccf868d0253b09895af29f811a3e3393 /internal/ui/subscription_submit.go | |
parent | 120aabfbcef4ef453d70861aece3b107b603a911 (diff) | |
download | v2-14e25ab9fe09b9951b38e56af2bdff7a0737b280.tar.gz v2-14e25ab9fe09b9951b38e56af2bdff7a0737b280.tar.zst v2-14e25ab9fe09b9951b38e56af2bdff7a0737b280.zip |
Refactor HTTP Client and LocalizedError packages
Diffstat (limited to 'internal/ui/subscription_submit.go')
-rw-r--r-- | internal/ui/subscription_submit.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/internal/ui/subscription_submit.go b/internal/ui/subscription_submit.go index 41e75a4a..ce444d79 100644 --- a/internal/ui/subscription_submit.go +++ b/internal/ui/subscription_submit.go @@ -10,6 +10,7 @@ import ( "miniflux.app/v2/internal/http/request" "miniflux.app/v2/internal/http/response/html" "miniflux.app/v2/internal/http/route" + "miniflux.app/v2/internal/locale" "miniflux.app/v2/internal/model" feedHandler "miniflux.app/v2/internal/reader/handler" "miniflux.app/v2/internal/reader/subscription" @@ -43,9 +44,9 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) { v.Set("hasProxyConfigured", config.Opts.HasHTTPClientProxyConfigured()) subscriptionForm := form.NewSubscriptionForm(r) - if err := subscriptionForm.Validate(); err != nil { + if validationErr := subscriptionForm.Validate(); validationErr != nil { v.Set("form", subscriptionForm) - v.Set("errorMessage", err.Error()) + v.Set("errorMessage", validationErr.Translate(user.Language)) html.OK(w, r, v.Render("add_subscription")) return } @@ -55,7 +56,7 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) { rssbridgeURL = intg.RSSBridgeURL } - subscriptions, findErr := subscription.FindSubscriptions( + subscriptions, localizedError := subscription.FindSubscriptions( subscriptionForm.URL, subscriptionForm.UserAgent, subscriptionForm.Cookie, @@ -65,9 +66,9 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) { subscriptionForm.AllowSelfSignedCertificates, rssbridgeURL, ) - if findErr != nil { + if localizedError != nil { v.Set("form", subscriptionForm) - v.Set("errorMessage", findErr) + v.Set("errorMessage", localizedError.Translate(user.Language)) html.OK(w, r, v.Render("add_subscription")) return } @@ -76,10 +77,10 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) { switch { case n == 0: v.Set("form", subscriptionForm) - v.Set("errorMessage", "error.subscription_not_found") + v.Set("errorMessage", locale.NewLocalizedError("error.subscription_not_found").Translate(user.Language)) html.OK(w, r, v.Render("add_subscription")) case n == 1: - feed, err := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{ + feed, localizedError := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{ CategoryID: subscriptionForm.CategoryID, FeedURL: subscriptions[0].URL, Crawler: subscriptionForm.Crawler, @@ -95,9 +96,9 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) { UrlRewriteRules: subscriptionForm.UrlRewriteRules, FetchViaProxy: subscriptionForm.FetchViaProxy, }) - if err != nil { + if localizedError != nil { v.Set("form", subscriptionForm) - v.Set("errorMessage", err) + v.Set("errorMessage", localizedError.Translate(user.Language)) html.OK(w, r, v.Render("add_subscription")) return } |