@scaffoldly/serverless-util
Version:
Scaffoldly Serverless Helper Functionality
21 lines • 885 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpError = void 0;
const ALLOWED_STATUS_CODES = [400, 401, 403, 404, 422, 429, 500, 502, 504];
class HttpError extends Error {
constructor(statusCode, message, context = {}) {
let actualStatusCode = statusCode;
let actualName = `HTTP Error ${statusCode}`;
// Serverless only supports the above status codes, make sure the status code is in the list, if not set it to 500
if (ALLOWED_STATUS_CODES.indexOf(statusCode) === -1) {
actualStatusCode = 500;
actualName = `${actualName} [Original Status Code: ${statusCode}]`;
}
super(message);
this.name = actualName;
this.statusCode = actualStatusCode;
this.context = context || {};
}
}
exports.HttpError = HttpError;
//# sourceMappingURL=errors.js.map
;