diff --git a/libraries/o-error/README.md b/libraries/o-error/README.md index e236e0b4d1..2a298fbc2e 100644 --- a/libraries/o-error/README.md +++ b/libraries/o-error/README.md @@ -6,7 +6,7 @@ Light-weight helpers for handling JavaScript Errors in node.js and the browser. - Get long stack traces across async functions and callbacks with `OError.tag`. -- Easily make custom `Error` subclasses, optionally with HTTP status codes. +- Easily make custom `Error` subclasses. - Wrap internal errors, preserving the original errors for logging as `causes`. - Play nice with error logging services by keeping data in attached `info` objects instead of the error message. diff --git a/libraries/o-error/http.js b/libraries/o-error/http.js deleted file mode 100644 index f5e03ec05f..0000000000 --- a/libraries/o-error/http.js +++ /dev/null @@ -1,89 +0,0 @@ -const OError = require('./index') - -class HttpError extends OError { - constructor({ message, info, ...options }) { - super(message, info) - this.statusCode = options.statusCode || 500 - } -} - -class InternalServerError extends HttpError { - constructor(options) { - super({ message: 'Internal Server Error', statusCode: 500, ...options }) - } -} - -class ServiceUnavailableError extends HttpError { - constructor(options) { - super({ message: 'Service Unavailable', statusCode: 503, ...options }) - } -} - -class BadRequestError extends HttpError { - constructor(options) { - super({ message: 'Bad Request', statusCode: 400, ...options }) - } -} - -class UnauthorizedError extends HttpError { - constructor(options) { - super({ message: 'Unauthorized', statusCode: 401, ...options }) - } -} - -class ForbiddenError extends HttpError { - constructor(options) { - super({ message: 'Forbidden', statusCode: 403, ...options }) - } -} - -class NotFoundError extends HttpError { - constructor(options) { - super({ message: 'Not Found', statusCode: 404, ...options }) - } -} - -class MethodNotAllowedError extends HttpError { - constructor(options) { - super({ message: 'Method Not Allowed', statusCode: 405, ...options }) - } -} - -class NotAcceptableError extends HttpError { - constructor(options) { - super({ message: 'Not Acceptable', statusCode: 406, ...options }) - } -} - -class ConflictError extends HttpError { - constructor(options) { - super({ message: 'Conflict', statusCode: 409, ...options }) - } -} - -class UnprocessableEntityError extends HttpError { - constructor(options) { - super({ message: 'Unprocessable Entity', statusCode: 422, ...options }) - } -} - -class TooManyRequestsError extends HttpError { - constructor(options) { - super({ message: 'Too Many Requests', statusCode: 429, ...options }) - } -} - -module.exports = { - HttpError, - InternalServerError, - ServiceUnavailableError, - BadRequestError, - UnauthorizedError, - ForbiddenError, - NotFoundError, - MethodNotAllowedError, - NotAcceptableError, - ConflictError, - UnprocessableEntityError, - TooManyRequestsError, -} diff --git a/libraries/o-error/test/http.test.js b/libraries/o-error/test/http.test.js deleted file mode 100644 index 94886ee854..0000000000 --- a/libraries/o-error/test/http.test.js +++ /dev/null @@ -1,32 +0,0 @@ -const { expect } = require('chai') - -const HttpErrors = require('../http') - -const { expectError } = require('./support') - -describe('OError/http', function () { - it('is a valid OError', function () { - function foo() { - throw new HttpErrors.ConflictError() - } - - try { - foo() - } catch (error) { - expectError(error, { - name: 'ConflictError', - klass: HttpErrors.ConflictError, - message: 'ConflictError: Conflict', - firstFrameRx: /foo/, - }) - } - }) - - it('has status code', function () { - try { - throw new HttpErrors.ConflictError() - } catch (e) { - expect(e.statusCode).to.equal(409) - } - }) -})