Skip to content

A small JavaScript library to help handle errors in APIs.

License

Notifications You must be signed in to change notification settings

femto-apps/lib-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
    }
}

About

A small JavaScript library to help handle errors in APIs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published