Custom errors

npm install error
25 downloads in the last day
77 downloads in the last week
303 downloads in the last month


Custom errors


var ValidationError = require("error/validation")
var OptionError = require("error/option")

var error = ValidationError([{
  message: "Please enter required field",
  attribute: "name"
}, {
  message: "Password must be at least 10 characters",
  attribute: "password"

console.log("error.errors", error.errors)

var error = OptionError("Something went wrong", metaData)

console.log("error.option", error.option)

Typed Error

var TypedError = require("error/typed")

var ServerError = TypedError({
  type: 'server.5xx.error',
  message: '{title} server error, status={statusCode}'
var ClientError = TypedError({
  type: 'client.4xx.error',
  message: '{title} client error, status={statusCode}'

var error = ServerError({
  title:'some title', 
  statusCode: 500
var error2 = ClientError({
  title: 'some title', 
  statusCode: 404


npm install error


  • Raynos

MIT Licenced

npm loves you