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
MIT Licenced