Skip to content

Commit

Permalink
🏭 Add fetch error catcher. #63
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Nov 27, 2019
1 parent 9655b46 commit 1794327
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 31 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ wretch("...").opts()
*Catchers can be chained.*
| [badRequest](#badrequestcb-error-wretchererror-originalrequest-wretcher--any) | [unauthorized](#unauthorizedcb-error-wretchererror-originalrequest-wretcher--any) | [forbidden](#forbiddencb-error-wretchererror-originalrequest-wretcher--any) | [notFound](#notfoundcb-error-wretchererror-originalrequest-wretcher--any) | [timeout](#timeoutcb-error-wretchererror-originalrequest-wretcher--any) | [internalError](#internalerrorcb-error-wretchererror-originalrequest-wretcher--any) | [error](#errorerrorid-number--string-cb-error-wretchererror-originalrequest-wretcher--any) |
| [badRequest](#badrequestcb-error-wretchererror-originalrequest-wretcher--any) | [unauthorized](#unauthorizedcb-error-wretchererror-originalrequest-wretcher--any) | [forbidden](#forbiddencb-error-wretchererror-originalrequest-wretcher--any) | [notFound](#notfoundcb-error-wretchererror-originalrequest-wretcher--any) | [timeout](#timeoutcb-error-wretchererror-originalrequest-wretcher--any) | [internalError](#internalerrorcb-error-wretchererror-originalrequest-wretcher--any) | [error](#errorerrorid-number--string-cb-error-wretchererror-originalrequest-wretcher--any) | [fetchError](#fetcherrorcb-error-networkerror-originalrequest-wretcher--any)
|-----|-----|-----|-----|-----|-----|-----|
```ts
Expand All @@ -723,6 +723,7 @@ wretch("...")
.timeout(err => console.log(err.status))
.internalError(err => console.log(err.status))
.error(418, err => console.log(err.status))
.fetchError(err => console.log(err))
.res()
```
Expand Down Expand Up @@ -754,6 +755,10 @@ Syntactic sugar for `error(500, cb)`.
Catches a specific error given its code or name and perform the callback.
#### fetchError(cb: (error: NetworkError, originalRequest: Wretcher) => any)
Catches any error thrown by the fetch function and perform the callback.
---------
The original request is passed along the error and can be used in order to perform an additional request.
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle/wretch.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/bundle/wretch.esm.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 1794327

Please sign in to comment.