Skip to content

Commit

Permalink
Add ability to check for specific api error type
Browse files Browse the repository at this point in the history
  • Loading branch information
knor-el-snor committed Feb 12, 2020
1 parent e5dc99d commit 38d44b8
Show file tree
Hide file tree
Showing 5 changed files with 3,160 additions and 2,398 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,20 @@ throw new ApiError(400, errors.BAD_REQUEST);

## Error parsing

### isApiError(apiError)
### isApiError(apiError, type?)

Will return boolean indicating whether error is instance of `ApiError`.
Can also be used to provide an extra check matching a specific error type (will only match code, not message)

```javascript
// Will return true
isApiError(new BadRequestError())

// Will return false
isApiError(new Error('Something'))

// Will return true
isApiError(new BadRequestError(errors.MY_CUSTOM_ERROR), errors.MY_CUSTOM_ERROR)
```

> Will automatically cast to ApiError if succeeds and using Typescript
Expand Down
Loading

0 comments on commit 38d44b8

Please sign in to comment.