Skip to content

Commit 692ce6b

Browse files
feat(errors): add support for HTTP 422 errors (#26)
1 parent bd273ec commit 692ce6b

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ var (
7676
ErrTagNotFound = errors.New(invalidTagMsg)
7777
// ErrDuplicateApp is returned when create an app with an ID that already exists
7878
ErrDuplicateApp = errors.New(duplicateIDMsg)
79+
// ErrUnprocessable is returned when the controller throws a 422.
80+
ErrUnprocessable = errors.New("Unable to process your request.")
7981
)
8082

8183
func checkForErrors(res *http.Response) error {
@@ -175,6 +177,8 @@ func checkForErrors(res *http.Response) error {
175177
return ErrMethodNotAllowed
176178
case 409:
177179
return ErrConflict
180+
case 422:
181+
return ErrUnprocessable
178182
case 500:
179183
return ErrServerError
180184
default:

errors_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ func TestErrors(t *testing.T) {
243243
},
244244
expected: ErrConflict,
245245
},
246+
errorTest{
247+
res: &http.Response{
248+
StatusCode: 422,
249+
Body: readCloser(""),
250+
},
251+
expected: ErrUnprocessable,
252+
},
246253
errorTest{
247254
res: &http.Response{
248255
StatusCode: 500,

0 commit comments

Comments
 (0)