Skip to content

Commit

Permalink
fix: handle single error responses (#49)
Browse files Browse the repository at this point in the history
* fix: handle single error responses

* fix: handle null or undefined errors
  • Loading branch information
connorlindsey authored Jan 24, 2024
1 parent 8e184bb commit 2d1609d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/knock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ class Knock {
throw new BadRequestException(code, message, requestID);
}
case 422: {
const { errors } = data;
// Format errors as an array before passing to exception constructor
const errors = !data.errors
? []
: Array.isArray(data.errors)
? data.errors
: [data.errors];

throw new UnprocessableEntityException(errors, requestID);
}
case 404: {
Expand Down

0 comments on commit 2d1609d

Please sign in to comment.