From ada19747c76596898d9ff10078b8c320af5ee5d2 Mon Sep 17 00:00:00 2001 From: Alexei Yuzhakov Date: Mon, 2 Sep 2024 14:04:31 +0100 Subject: [PATCH] Show reusable command in the case of auth error --- internal/api/json/types.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/api/json/types.go b/internal/api/json/types.go index eac0929..6a832c8 100644 --- a/internal/api/json/types.go +++ b/internal/api/json/types.go @@ -2,7 +2,10 @@ package json -import "github.com/plesk/pleskapp/plesk/internal/locales" +import ( + "github.com/plesk/pleskapp/plesk/internal/locales" + "net/url" +) type jsonError struct { Code int `json:"code"` @@ -88,8 +91,14 @@ type authError struct { } func (e authError) Error() string { + serverUrl, err := url.Parse(e.server) + host := e.server + if err == nil { + host = serverUrl.Hostname() + } + if e.needReauth { - return locales.L.Get("api.errors.auth.failed.reauth", e.server) + return locales.L.Get("api.errors.auth.failed.reauth", host) } - return locales.L.Get("api.errors.auth.wrong.pass", e.server) + return locales.L.Get("api.errors.auth.wrong.pass", host) }