UnexpectedStatusError reports a successful response whose status the caller did not expect. The request methods on Client convert every non-2xx response into an HTTPError, so a call site that requires one specific status can only ever be surprised by a different 2xx. Passing such a response to Hand
(resp *http.Response)
| 293 | // response to HandleHTTPError would ask an error parser to explain a success, so this is used |
| 294 | // instead. The caller remains responsible for closing the response body stream. |
| 295 | func UnexpectedStatusError(resp *http.Response) error { |
| 296 | if resp.Request != nil { |
| 297 | return fmt.Errorf("unexpected HTTP %d for %s %s", resp.StatusCode, resp.Request.Method, resp.Request.URL) |
| 298 | } |
| 299 | return fmt.Errorf("unexpected HTTP %d", resp.StatusCode) |
| 300 | } |
| 301 | |
| 302 | // handleRequestError converts a request error into an HTTPError or GraphQLError, first adding any |
| 303 | // endpoint scopes to the error's headers so that the scopes suggestion generated by handleResponse |