MCPcopy Create free account
hub / github.com/cloudfoundry/credhub-cli / checkForServerError

Method checkForServerError

credhub/request.go:80–104  ·  view source on GitHub ↗
(resp *http.Response)

Source from the content-addressed store, hash-verified

78}
79
80func (ch *CredHub) checkForServerError(resp *http.Response) error {
81 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
82 defer resp.Body.Close()
83 body, err := io.ReadAll(resp.Body)
84 if err != nil {
85 return errors.New("The response body could not be read: " + err.Error())
86 }
87
88 var respErr error
89
90 switch resp.StatusCode {
91 case http.StatusNotFound:
92 respErr = &NotFoundError{}
93 default:
94 respErr = &Error{}
95 }
96
97 if err := json.Unmarshal(body, &respErr); err != nil {
98 return errors.New("The response body could not be decoded: " + err.Error())
99 }
100 return respErr
101 }
102
103 return nil
104}
105
106func dumpRequest(req *http.Request) {
107 dump, err := httputil.DumpRequestOut(req, true)

Callers 3

requestMethod · 0.95
generateCredentialMethod · 0.95
InterpolateStringMethod · 0.95

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected