From b57f03381e4bccba2963cebabe51a9cf32bd96dd Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 7 May 2026 12:44:21 -0400 Subject: implement POST /validate-cover --- err.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'err.go') diff --git a/err.go b/err.go index e05d1ff..cb79500 100644 --- a/err.go +++ b/err.go @@ -6,6 +6,28 @@ import ( "net/http" ) +// pkgErr formats an error to be returned to the package user. +func pkgErr(err error) error { + return fmt.Errorf("lulu: %w", err) +} + +// pkgErrf formats an error with a message to be returned to the package user. +func pkgErrf(err error, format string, a ...any) error { + return fmt.Errorf("lulu: %s: %w", + fmt.Sprintf(format, a...), + err) +} + +type errEncReq struct { + payload any + path string + error +} + +func (e errEncReq) Error() string { + return fmt.Sprintf("error encoding request body %v for %s: %v", e.payload, e.path, e.error) +} + type errResp struct { *http.Response } @@ -14,7 +36,7 @@ func (e errResp) Error() string { resp := e.Response req := resp.Request body, _ := io.ReadAll(resp.Body) - return fmt.Sprintf("lulu: %s %s: %s: %s", req.Method, req.URL, resp.Status, body) + return fmt.Sprintf("%s %s: %s: %s", req.Method, req.URL, resp.Status, body) } type errReadResp struct { @@ -24,7 +46,7 @@ type errReadResp struct { func (e errReadResp) Error() string { req := e.Response.Request - return fmt.Sprintf("lulu: %s %s: error reading response body: %v", + return fmt.Sprintf("%s %s: error reading response body: %v", req.Method, req.URL, e.error) } @@ -36,6 +58,6 @@ type errDecResp struct { func (e errDecResp) Error() string { req := e.Response.Request - return fmt.Sprintf("lulu: %s %s: error decoding response body %q: %v", + return fmt.Sprintf("%s %s: error decoding response body %q: %v", req.Method, req.URL, string(e.body), e.error) } -- cgit v1.2.3