MCPcopy Index your code
hub / github.com/dnote/dnote / checkRespErr

Function checkRespErr

pkg/cli/client/client.go:141–156  ·  view source on GitHub ↗

checkRespErr checks if the given http response indicates an error. It returns a boolean indicating if the response is an error, and a decoded error message.

(res *http.Response)

Source from the content-addressed store, hash-verified

139// checkRespErr checks if the given http response indicates an error. It returns a boolean indicating
140// if the response is an error, and a decoded error message.
141func checkRespErr(res *http.Response) error {
142 if res.StatusCode < 400 {
143 return nil
144 }
145
146 body, err := io.ReadAll(res.Body)
147 if err != nil {
148 return errors.Wrapf(err, "server responded with %d but client could not read the response body", res.StatusCode)
149 }
150
151 bodyStr := string(body)
152 return &HTTPError{
153 StatusCode: res.StatusCode,
154 Message: strings.TrimRight(bodyStr, "\n"),
155 }
156}
157
158func checkContentType(res *http.Response, options *requestOptions) error {
159 expected := getExpectedContentType(options)

Callers 1

doReqFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected