Package Exports
- server-error
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 (server-error) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
server-error 
Create an error and send it to a logger.
Usage
const serverError = require('server-error')
const bole = require('bole')
const log = bole('my-package')
const error = serverError(log)
error.client('oh no!')
// {
// type: 'client',
// statusCode: 400,
// message: 'oh no!',
// url: null
// }
error.client({ message: 'not found', statusCode: 404 })
// {
// type: 'client',
// statusCode: 404,
// message: 'not found',
// url: null
// }
error.server({ message: 'something went wrong', url: 'http://api.foo.io' })
// {
// type: 'server',
// statusCode: 500,
// message: 'something went wrong',
// url: 'http://api.foo.io'
// }
error.wrap(new Error('something critical went wrong'))
// {
// type: 'server',
// statusCode: 500,
// message: 'Internal Server Error'
// }API
error = serverError(log, opts?)
Create a new error object that logs to a logger. Takes options:
- logLevel: which level to log. Defaults to
'info'
error.client(message)
Create a new client error that defaults to statusCode 400. Takes either a string or object.
error.server(message)
Create a new server error that defaults to statusCode 500. Takes either a string or object.
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