(expectedStatus int, action string, response *simpleResponse, err error)
| 1155 | } |
| 1156 | |
| 1157 | func checkStatus(expectedStatus int, action string, response *simpleResponse, err error) error { |
| 1158 | if err != nil { |
| 1159 | errStr := err.Error() |
| 1160 | if urlErr, isURLErr := err.(*url.Error); isURLErr { |
| 1161 | errStr = fmt.Sprintf("%s %s: %s", urlErr.Op, urlErr.URL, urlErr.Err) |
| 1162 | } |
| 1163 | return fmt.Errorf("Error %s: %s", action, errStr) |
| 1164 | } else if response.StatusCode != expectedStatus { |
| 1165 | errInfo, err := response.ErrorInfo() |
| 1166 | if err != nil { |
| 1167 | return fmt.Errorf("Error %s: %s (HTTP %d)", action, err.Error(), response.StatusCode) |
| 1168 | } |
| 1169 | return FormatError(action, errInfo) |
| 1170 | } |
| 1171 | return nil |
| 1172 | } |
| 1173 | |
| 1174 | // FormatError annotates an HTTP response error with user-friendly messages |
| 1175 | func FormatError(action string, err error) error { |
no test coverage detected
searching dependent graphs…