Skip to content

lvivier/error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

error

Custom error constructors (without all the fuss).

Our errors have all the bells and whistles:

var error = require('error')
var NotFoundError = error('NotFoundError', {status:404})
var err = new NotFoundError('ohnoes')

err
//-> NotFoundError {}
err instanceof NotFoundError
//-> true
err instanceof Error
//-> true
err.name === 'NotFoundError'
//-> true
err.message
//-> 'ohnoes'
err.status
//-> 404

Install

With component or npm:

$ component install lvivier/error

$ npm install lvivier/error

Usage

error(name, [parent], [opts])

  • returns a Function
  • parent is the prototype, or Error if omitted
  • opts is an object whose members will become properties of the error instance
  • opts.stack if set to false, errors won't have stack traces

About

Custom error constructors

Resources

Stars

Watchers

Forks

Packages

No packages published