ExpectJSONMime is a helper function that will assert the content type of the response is application/json.
(res *http.Response)
| 395 | // ExpectJSONMime is a helper function that will assert the content type |
| 396 | // of the response is application/json. |
| 397 | func ExpectJSONMime(res *http.Response) error { |
| 398 | contentType := res.Header.Get("Content-Type") |
| 399 | mimeType := parseMimeType(contentType) |
| 400 | if mimeType != "application/json" { |
| 401 | return xerrors.Errorf("unexpected non-JSON response %q", contentType) |
| 402 | } |
| 403 | return nil |
| 404 | } |
| 405 | |
| 406 | // ReadBodyAsError reads the response as a codersdk.Response, and |
| 407 | // wraps it in a codersdk.Error type for easy marshaling. |
no test coverage detected