summaryrefslogtreecommitdiff
path: root/i18nerr
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-02-06 14:09:45 +0100
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-02-19 14:15:07 +0100
commit2de1cd18c05a779b27f68adfb9d60a1277bb6d55 (patch)
tree4a75d91f430a4b0826ec0f12a503028deaf4f186 /i18nerr
parent6f7e32b6d9dcf4732dd0acbd89be77b42805a5ca (diff)
i18nerr + HTTP: Properly convert timeout errors
Diffstat (limited to 'i18nerr')
-rw-r--r--i18nerr/i18nerr.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/i18nerr/i18nerr.go b/i18nerr/i18nerr.go
index d513fdd..2dea504 100644
--- a/i18nerr/i18nerr.go
+++ b/i18nerr/i18nerr.go
@@ -7,15 +7,17 @@ import (
"fmt"
"sync"
+ "github.com/eduvpn/eduvpn-common/internal/http"
"github.com/eduvpn/eduvpn-common/internal/log"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
-var printers sync.Map
-var once sync.Once
-
+var (
+ printers sync.Map
+ once sync.Once
+)
// TranslatedInner defines errors that are used as inner causes but are still translated because they can happen frequently
func TranslatedInner(inner error) (string, bool) {
@@ -24,9 +26,10 @@ func TranslatedInner(inner error) (string, bool) {
unwrapped = errors.Unwrap(unwrapped)
}
+ var tErr *http.TimeoutError
switch {
- case errors.Is(inner, context.DeadlineExceeded):
- return printerOrNew(language.English).Sprintf("timeout reached"), false
+ case errors.As(inner, &tErr):
+ return printerOrNew(language.English).Sprintf("timeout reached for URL: '%s' and HTTP method: '%s'", tErr.URL, tErr.Method), false
case errors.Is(inner, context.Canceled):
return unwrapped.Error(), true
}
@@ -37,10 +40,10 @@ func TranslatedInner(inner error) (string, bool) {
// This translation key is later used to lookup translation
// The inner error always consists of the translation key and some formatting
type Error struct {
- key message.Reference
- args []interface{}
+ key message.Reference
+ args []interface{}
wrapped *Error
- Misc bool
+ Misc bool
}
func (e *Error) translated(t language.Tag) string {
@@ -81,7 +84,6 @@ func (e *Error) Translations() map[string]string {
return translations
}
-
// Unwrap returns the unwrapped error
// it does this by unwrapping the inner error
func (e *Error) Unwrap() error {
@@ -142,7 +144,7 @@ func NewInternal(disp string) *Error {
}
// NewInternalf creates an internal localised error from a display string and arguments
-func NewInternalf(disp string, args...interface{}) *Error {
+func NewInternalf(disp string, args ...interface{}) *Error {
return NewInternal(fmt.Sprintf(disp, args...))
}