Easily Return HTTP Errors from Spirit
Supports JSON, HTML, Text and dynamic errors.
import spiritError from 'spirit-error'
// tell spirit-error to create JSON responses
const error = spiritError({
type: 'json' // default
})
// inside a spirit function
return error.notFound
Returns this HTTP response:
HTTP/1.1 404 Not Found
Content-Type: application/json; charset=utf-8
{
"error": {
"message": "Not Found"
}
}
With npm installed, run
npm install --save spirit-error
or use yarn:
yarn add spirit-error