express-json-error
v1.2.0
Published
middleware handler for express json apis errors
Downloads
3
Maintainers
Readme
express-json-error
middleware handler for express json apis errors
import express from 'express'
import error from 'express-json-error'
express()
.get('/user/:code?', ({ params }, res, next) => {
const { code } = params
if (!code) {
throw { code: 404, message: 'user not found' } // call express-json-error via exception
} else {
next({ code: 404, message: 'user not found' }) // call express-json-error via next
}
})
.use(error({ advanced:false }))
.listen(3000)