ohnodeprecated

A wrapper library for HTTP error status codes

Usage no npm install needed!

<script type="module">
  import ohno from 'https://cdn.skypack.dev/ohno';
</script>

README

OhNo

Build Status Coverage Status JavaScript Style Guide

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() -- 400
  • ohno.unauthorized() -- 401
  • ohno.paymentRequired() -- 402
  • ohno.forbidden() -- 403
  • ohno.notFound() -- 404
  • ohno.methodNotAllowed() -- 405
  • ohno.notAcceptable() -- 406
  • ohno.proxyAuthenticationRequired() -- 407
  • ohno.requestTimeout() -- 408
  • ohno.conflict() -- 409
  • ohno.gone() -- 410
  • ohno.lengthRequired() -- 411
  • ohno.preconditionFailed() -- 412
  • ohno.payloadTooLarge() -- 413
  • ohno.uriTooLong() -- 414
  • ohno.unsupportedMediaType() -- 415
  • ohno.rangeNotSatisfiable() -- 416
  • ohno.expectationFailed() -- 417
  • ohno.teapot() -- 418
  • ohno.misdirectedRequest() -- 421
  • ohno.unprocessableEntity() -- 422
  • ohno.locked() -- 423
  • ohno.failedDependency() -- 424
  • ohno.unorderedCollection() -- 425
  • ohno.upgradeRequired() -- 426
  • ohno.preconditionRequired() -- 428
  • ohno.tooManyRequests() -- 429
  • ohno.requestHeaderFieldsTooLarge() -- 431
  • ohno.unavailableForLegalReasons() -- 451
  • ohno.internalServerError() -- 500
  • ohno.notImplemented() -- 501
  • ohno.badGateway() -- 502
  • ohno.serviceUnavailable() -- 503
  • ohno.gatewayTimeout() -- 504
  • ohno.httpVersionNotSupported() -- 505
  • ohno.variantAlsoNegotiates() -- 506
  • ohno.insufficientStorage() -- 507
  • ohno.loopDetected() -- 508
  • ohno.bandwidthLimitExceeded() -- 509
  • ohno.notExtended() -- 510
  • ohno.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()

License

MIT © Jason Maurer