Add unauthorized error check
Add check for unauthorized error code and explicitly set the error code if the content could not be parsed. Updated repository test for unauthorized tests and nit feedback. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
b4972a6bab
commit
3b5a2bbebc
2 changed files with 61 additions and 32 deletions
|
@ -52,6 +52,17 @@ func parseHTTPErrorResponse(r io.Reader) error {
|
|||
}
|
||||
|
||||
func handleErrorResponse(resp *http.Response) error {
|
||||
if resp.StatusCode == 401 {
|
||||
err := parseHTTPErrorResponse(resp.Body)
|
||||
if uErr, ok := err.(*UnexpectedHTTPResponseError); ok {
|
||||
return &v2.Error{
|
||||
Code: v2.ErrorCodeUnauthorized,
|
||||
Message: "401 Unauthorized",
|
||||
Detail: uErr.Response,
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode >= 400 && resp.StatusCode < 500 {
|
||||
return parseHTTPErrorResponse(resp.Body)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue