Package Exports
- @femto-apps/errors
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@femto-apps/errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Errors
An opinionated library to help you handle errors in APIs.
Usage
An example index file:
// 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:
{
"ERRNOTFOUND": {
"msg": "File {file} was not found.",
"code": 404
}
}