Socket
Book a DemoInstallSign in
Socket

@tfso/extended-error

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tfso/extended-error

An Extended Error class that support custom properties

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
3
Created
Source

extended-error

ExtendedError makes it easier to create Error with custom properties

installation

npm install @tfso/extended-error

Usage

const ExtendedError = require('extended-error')

let error = new ExtendedError('Not found', {status:404})

console.log(error.message)                      // Not found
console.log(error.status)                       // 404
console.log(error instanceof Error)             // true 
console.log(error instanceof ExtendedError)     // true 
console.log(error.stack)                        // 'Error: Not found\n    at repl:1:9\n ...

This:

throw new ExtendedError('Not found', {status:404})

is equivalent to:

let error = new Error('Not found')
error.status = 400
throw error

Credits

https://gist.github.com/slavafomin/b164e3e710a6fc9352c934b9073e7216

Keywords

error

FAQs

Package last updated on 12 Oct 2018

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