@femto-host/errors

1.0.0 • Public • Published

Errors

An opinionated library to help you handle errors in APIs.

Usage

An 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('ERRNOFOUND', { file: 'test.txt' })
})

An error file:

{
    "ERRNOTFOUND": {
        "msg": "File {file} was not found.",
        "code": 404
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @femto-host/errors

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

4.73 kB

Total Files

7

Last publish

Collaborators

  • codefined