@malijs/onerror
Version:
On error middleware for Mali
36 lines (24 loc) • 1.13 kB
Markdown
# @malijs/onerror
Mali on error middleware. Calls function with error and context.
The called function does not have access to control flow.
[](https://www.npmjs.com/package/@malijs/onerror)
[](https://travis-ci.org/malijs/onerror)
## API
<a name="module_@malijs/onerror"></a>
### @malijs/onerror ⇒ <code>function</code>
Mali on error middleware. Calls function with error and context. The called function does not
have access to control flow.
**Returns**: <code>function</code> - the middleware function
| Param | Type | Description |
| --- | --- | --- |
| fn | <code>function</code> | The function to call when an error occurs. Function has to have signature with signature <code>(err, ctx)</code> |
**Example**
```js
const onError = require('@malijs/onerror')
function errorLogger (err, ctx) {
console.log('Error on %s: %s', ctx.name, err.toString())
}
app.use(onError(errorLogger))
```
## License
Apache-2.0