README
OhNo
A wrapper library for HTTP error status codes in Node.
Getting Started
Installation
npm install ohno
Usage
const ohno = require('ohno')
ohno.notFound('Resource was not found')
{
isOhNo: true,
statusCode: 404,
errorName: 'Not Found',
isServerError: false,
responseBody: {
error: 'Resource was not found'
}
}
isOhNo
- A boolean to identify an error coming from this library
statusCode
- The HTTP status code
errorName
- The full error name
isServerError
- Whether it's a server error (>=500)
responseBody
- What you should send back in the response
You can also pass an object param to send extra data to the response.
ohno.notFound('Resource was not found', { extra: 'value' })
{
statusCode: 404,
errorName: 'Not Found',
isServerError: false,
responseBody: {
error: 'Resource was not found',
extra: 'value'
}
}
API
Errors By Name
ohno.badRequest()
-- 400ohno.unauthorized()
-- 401ohno.paymentRequired()
-- 402ohno.forbidden()
-- 403ohno.notFound()
-- 404ohno.methodNotAllowed()
-- 405ohno.notAcceptable()
-- 406ohno.proxyAuthenticationRequired()
-- 407ohno.requestTimeout()
-- 408ohno.conflict()
-- 409ohno.gone()
-- 410ohno.lengthRequired()
-- 411ohno.preconditionFailed()
-- 412ohno.payloadTooLarge()
-- 413ohno.uriTooLong()
-- 414ohno.unsupportedMediaType()
-- 415ohno.rangeNotSatisfiable()
-- 416ohno.expectationFailed()
-- 417ohno.teapot()
-- 418ohno.misdirectedRequest()
-- 421ohno.unprocessableEntity()
-- 422ohno.locked()
-- 423ohno.failedDependency()
-- 424ohno.unorderedCollection()
-- 425ohno.upgradeRequired()
-- 426ohno.preconditionRequired()
-- 428ohno.tooManyRequests()
-- 429ohno.requestHeaderFieldsTooLarge()
-- 431ohno.unavailableForLegalReasons()
-- 451ohno.internalServerError()
-- 500ohno.notImplemented()
-- 501ohno.badGateway()
-- 502ohno.serviceUnavailable()
-- 503ohno.gatewayTimeout()
-- 504ohno.httpVersionNotSupported()
-- 505ohno.variantAlsoNegotiates()
-- 506ohno.insufficientStorage()
-- 507ohno.loopDetected()
-- 508ohno.bandwidthLimitExceeded()
-- 509ohno.notExtended()
-- 510ohno.networkAuthenticationRequired()
-- 511
Errors By Code
ohno.__400()
ohno.__401()
ohno.__402()
ohno.__403()
ohno.__404()
ohno.__405()
ohno.__406()
ohno.__407()
ohno.__408()
ohno.__409()
ohno.__410()
ohno.__411()
ohno.__412()
ohno.__413()
ohno.__414()
ohno.__415()
ohno.__416()
ohno.__417()
ohno.__418()
ohno.__421()
ohno.__422()
ohno.__423()
ohno.__424()
ohno.__425()
ohno.__426()
ohno.__428()
ohno.__429()
ohno.__431()
ohno.__451()
ohno.__500()
ohno.__501()
ohno.__502()
ohno.__503()
ohno.__504()
ohno.__505()
ohno.__506()
ohno.__507()
ohno.__508()
ohno.__509()
ohno.__510()
ohno.__511()