parseErrorBody decodes an error response whose body has already been read. Split out of parseError so callers that need the raw bytes for their own purposes (see client_items_copy.go) produce byte-identical error values rather than a second, subtly different vocabulary.
(status int, body []byte)
| 3522 | // their own purposes (see client_items_copy.go) produce byte-identical |
| 3523 | // error values rather than a second, subtly different vocabulary. |
| 3524 | func parseErrorBody(status int, body []byte) error { |
| 3525 | var errResp struct { |
| 3526 | Error APIError `json:"error"` |
| 3527 | } |
| 3528 | if err := json.Unmarshal(body, &errResp); err == nil && errResp.Error.Message != "" { |
| 3529 | if errResp.Error.Code == "csrf_error" { |
| 3530 | errResp.Error.Message = "Session authentication error. Run 'pad auth login' to re-authenticate." |
| 3531 | } |
| 3532 | errResp.Error.Status = status |
| 3533 | return &errResp.Error |
| 3534 | } |
| 3535 | return &StatusError{Status: status, Body: string(body)} |
| 3536 | } |
| 3537 | |
| 3538 | // StatusError is a non-2xx answer whose body was not the server's JSON error |
| 3539 | // envelope: a proxy's page, an empty body, a stub. It used to be a plain |
no outgoing calls
no test coverage detected