Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import HttpErrors from 'http-errors';
const A: HttpErrors.HttpError = new HttpErrors.HttpError();
const B: HttpErrors.HttpError = HttpErrors();
const C: HttpErrors.HttpError = HttpErrors(200, 'foo', {});
// $ExpectError
const D: HttpErrors.HttpError = HttpErrors('500');
const E: HttpErrors.NotFound = new HttpErrors.NotFound();
const F: HttpErrors.HttpError = new HttpErrors.LengthRequired;
const G: HttpErrors.HttpError = new HttpErrors.HttpError('foo');
(F.expose: bool);
(F.message: string);
(F.status: number);
(F.statusCode: number);
it('should have a static property exporting `HttpError` from http-errors library', () => {
const CreateError = require('http-errors');
assert.notEqual(Koa.HttpError, undefined);
assert.deepStrictEqual(Koa.HttpError, CreateError.HttpError);
assert.throws(() => { throw new CreateError(500, 'test error'); }, Koa.HttpError);
});
});
const createUnknownError = exports.unknown = (cause) => {
if (cause instanceof httpErrors.HttpError) {
return cause;
}
const message = cause instanceof Error ? cause.message : String(cause);
const error = createError('Internal Server Error', 'UnknownError', message);
if (cause instanceof Error) {
error.stack = cause.stack;
} else {
Error.captureStackTrace(error, createUnknownError);
}
return error;
};
notExtended: function notExtended (message) {
return new createError.NotExtended(message)
},
networkAuthenticationRequired: function networkAuthenticationRequired (message) {
return new createError.NetworkAuthenticationRequired(message)
}
}
function getHttpError (code, message) {
return httpErrors[statusCodesMap[code + '']](message)
}
module.exports = httpErrors
module.exports.getHttpError = getHttpError
module.exports.HttpError = createError.HttpError