server-error
Create an error and send it to a logger.
Usage
const serverError = const bole = const log = const error = error// {// type: 'client',// statusCode: 400,// message: 'oh no!',// url: null// } error// {// type: 'client',// statusCode: 404,// message: 'not found',// url: null// } error// {// type: 'server',// statusCode: 500,// message: 'something went wrong',// url: 'http://api.foo.io'// } error// {// type: 'server',// statusCode: 500,// message: 'Internal Server Error'// }
API
error = serverError(log, opts?)
Create a new error object that logs to a logger.
error.client(message)
Create a new client error that defaults to statusCode 400. Takes either a
string or object. Uses log.warn
.
error.server(message)
Create a new server error that defaults to statusCode 500. Takes either a
string or object. Uses log.error
.
error.wrap(error)
Wrap an existing error into an error that can be returned to the client. Useful
to handle unexpected state without leaking information to the outside world.
Uses statusCode 500 and log.error
.
Installation
$ npm install server-error