From a54f50d2a6883e8ba6f1098bdc17a390ee3293f3 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Fri, 7 Nov 2025 10:09:39 -0300 Subject: [PATCH] chore: use `http.StatusText` Co-authored-by: Christian Rocha --- errors.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/errors.go b/errors.go index 0e843640cd771648bb89df64fe2cf3d02a2abcdd..479b0c1a45eefe84bfcf11064865eb44b80f5b5f 100644 --- a/errors.go +++ b/errors.go @@ -3,6 +3,7 @@ package fantasy import ( "fmt" "net/http" + "strings" "github.com/charmbracelet/x/exp/slice" ) @@ -69,19 +70,7 @@ func (e RetryError) Unwrap() error { return nil } -var statusCodeToTitle = map[int]string{ - http.StatusBadRequest: "bad request", - http.StatusUnauthorized: "authentication failed", - http.StatusForbidden: "permission denied", - http.StatusNotFound: "resource not found", - http.StatusTooManyRequests: "rate limit exceeded", - http.StatusInternalServerError: "internal server error", - http.StatusBadGateway: "bad gateway", - http.StatusServiceUnavailable: "service unavailable", - http.StatusGatewayTimeout: "gateway timeout", -} - // ErrorTitleForStatusCode returns a human-readable title for a given HTTP status code. func ErrorTitleForStatusCode(statusCode int) string { - return statusCodeToTitle[statusCode] + return strings.ToLower(http.StatusText(statusCode)) }