Socket
Book a DemoInstallSign in
Socket

server-error

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

server-error

Create an error and send it to a logger

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

server-error stability

npm version build status test coverage downloads js-standard-style

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.

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

License

MIT

Keywords

bole

FAQs

Package last updated on 30 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts