lfsapi/errors.go: create a NewUnprocessableEntityError when appropriate

In the previous commit, we introduced a new type for detecting when the
server sent back an HTTP 422.

In this commit, let's use that and detect when we get a situation in
which:

    res.StatusCode == 422

And create+return the new error appropriately.
This commit is contained in:
Taylor Blau 2018-07-31 13:23:16 -05:00
parent 013c02d010
commit 40929cc7f0
2 changed files with 5 additions and 8 deletions

@ -58,6 +58,10 @@ func (c *Client) handleResponse(res *http.Response) error {
return errors.NewAuthError(err) return errors.NewAuthError(err)
} }
if res.StatusCode == 422 {
return errors.NewUnprocessableEntityError(err)
}
if res.StatusCode > 499 && res.StatusCode != 501 && res.StatusCode != 507 && res.StatusCode != 509 { if res.StatusCode > 499 && res.StatusCode != 501 && res.StatusCode != 507 && res.StatusCode != 509 {
return errors.NewFatalError(err) return errors.NewFatalError(err)
} }
@ -92,6 +96,7 @@ var (
401: "Authorization error: %s\nCheck that you have proper access to the repository", 401: "Authorization error: %s\nCheck that you have proper access to the repository",
403: "Authorization error: %s\nCheck that you have proper access to the repository", 403: "Authorization error: %s\nCheck that you have proper access to the repository",
404: "Repository or object not found: %s\nCheck that it exists and that you have proper access to it", 404: "Repository or object not found: %s\nCheck that it exists and that you have proper access to it",
422: "Unprocessable entity: %s",
429: "Rate limit exceeded: %s", 429: "Rate limit exceeded: %s",
500: "Server error: %s", 500: "Server error: %s",
501: "Not Implemented: %s", 501: "Not Implemented: %s",

@ -65,14 +65,6 @@ begin_test "push: upload file with storage 410"
) )
end_test end_test
begin_test "push: upload file with storage 422"
(
set -e
push_fail_test "status-storage-422"
)
end_test
begin_test "push: upload file with storage 500" begin_test "push: upload file with storage 500"
( (
set -e set -e