MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / parseErrorBody

Function parseErrorBody

internal/cli/client.go:3524–3536  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

3522// their own purposes (see client_items_copy.go) produce byte-identical
3523// error values rather than a second, subtly different vocabulary.
3524func 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

Callers 2

postCopyDataMethod · 0.85
parseErrorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected