diff options
Diffstat (limited to 'err.go')
| -rw-r--r-- | err.go | 19 |
1 files changed, 17 insertions, 2 deletions
@@ -18,6 +18,7 @@ func pkgErrf(err error, format string, a ...any) error { err) } +// error encoding request type errEncReq struct { payload any path string @@ -28,17 +29,19 @@ 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 { +// server responded with the wrong status +type errRespStatus struct { *http.Response } -func (e errResp) Error() string { +func (e errRespStatus) Error() string { resp := e.Response req := resp.Request body, _ := io.ReadAll(resp.Body) return fmt.Sprintf("%s %s: %s: %s", req.Method, req.URL, resp.Status, body) } +// error reading response type errReadResp struct { *http.Response error @@ -50,6 +53,7 @@ func (e errReadResp) Error() string { req.Method, req.URL, e.error) } +// error decoding response type errDecResp struct { *http.Response body []byte @@ -61,3 +65,14 @@ func (e errDecResp) Error() string { return fmt.Sprintf("%s %s: error decoding response body `%s`: %v", req.Method, req.URL, string(e.body), e.error) } + +// server returned a bad response +type errResp struct { + *http.Response + error +} + +func (e errResp) Error() string { + req := e.Response.Request + return fmt.Sprintf("%s %s: bad response: %v", req.Method, req.URL, e.error) +} |