Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Error handling utilities for node

branch: master

4.1.1

latest commit f4f47b7208
Raynos (Jake Verbaten) authored
README.md

error

Custom errors

Example

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
})

Installation

npm install error

Contributors

  • Raynos

MIT Licenced

Something went wrong with that request. Please try again.