MCPcopy Index your code
hub / github.com/coder/coder / ExpectJSONMime

Function ExpectJSONMime

codersdk/client.go:397–404  ·  view source on GitHub ↗

ExpectJSONMime is a helper function that will assert the content type of the response is application/json.

(res *http.Response)

Source from the content-addressed store, hash-verified

395// ExpectJSONMime is a helper function that will assert the content type
396// of the response is application/json.
397func 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.

Callers 5

runOnceMethod · 0.92
readRawBodyAsErrorFunction · 0.85
BuildInfoMethod · 0.85
ReadBodyAsErrorFunction · 0.85

Calls 3

parseMimeTypeFunction · 0.85
GetMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected