Skip to content

Commit

Permalink
🏭 Add global catchers with the catcher method
Browse files Browse the repository at this point in the history
  • Loading branch information
elbywan committed Oct 3, 2017
1 parent ad0d612 commit 04b5cb9
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 307 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://coveralls.io/github/elbywan/wretch?branch=master"><img src="https://coveralls.io/repos/github/elbywan/wretch/badge.svg?branch=master" alt="Coverage Status" /></a>
</h1>
<h4 align="center">
A tiny (&lt; 1.4Kb g-zipped) wrapper built around fetch with an intuitive syntax.
A tiny (&lt; 1.5Kb g-zipped) wrapper built around fetch with an intuitive syntax.
</h4>
<h5 align="center">
<i>f[ETCH] [WR]apper</i>
Expand Down Expand Up @@ -254,6 +254,21 @@ wretch("http://server/which/returns/an/error/with/a/json/body")
}
```
#### catcher(code: number, catcher: (error: WretcherError) => void)
Adds a [catcher](https://github.com/elbywan/wretch#catchers) which will be called on every subsequent request error.
Very useful when you need to perform a repetitive action on a specific error code.
```js
const w = wretcher()
.catcher(404, err => redirect("/routes/notfound", err.message))
.catcher(500, err => flashMessage("internal.server.error"))

// No need to catch 404 or 500 code, they are already taken care of.
w.url("http://myapi.com/get/something").get().json(json => /* ... */)
```
#### options(options: Object)
Set the fetch options.
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle/wretch.js

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

Loading

0 comments on commit 04b5cb9

Please sign in to comment.