mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-12 00:35:03 +00:00
Remove HTTPErrors from v3
This commit is contained in:
parent
90494fd75f
commit
4b0060f0b1
3 changed files with 1 additions and 122 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
})
|
Loading…
Add table
Reference in a new issue