(resp *http.Response)
| 78 | } |
| 79 | |
| 80 | func (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 | |
| 106 | func dumpRequest(req *http.Request) { |
| 107 | dump, err := httputil.DumpRequestOut(req, true) |
no test coverage detected