https://github.com/femto-apps/lib-errors
A small JavaScript library to help handle errors in APIs.
https://github.com/femto-apps/lib-errors
api-error error-handling node-js nodejs
Last synced: 22 days ago
JSON representation
A small JavaScript library to help handle errors in APIs.
- Host: GitHub
- URL: https://github.com/femto-apps/lib-errors
- Owner: femto-apps
- License: mit
- Created: 2019-01-26T22:25:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T11:35:42.000Z (about 3 years ago)
- Last Synced: 2024-03-26T19:21:52.215Z (almost 2 years ago)
- Topics: api-error, error-handling, node-js, nodejs
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
### Errors
An opinionated library to help you handle errors in APIs.
#### Usage
An example index file:
```javascript
// require the module
const Errors = require('@femto-host/errors')
// initialise errors
const errors = new Errors('path/to/errors.json')
// add the errors function to your express `res` object.
app.use('/api', (req, res, next) => {
errors(res)
next()
})
// register errors.
app.get('/api/test', (req, res) => {
res.error('ERRNOTFOUND', { file: 'test.txt' })
})
```
An example error file:
```json
{
"ERRNOTFOUND": {
"msg": "File {file} was not found.",
"code": 404
}
}
```