cassava
Version:
AWS API Gateway Router
23 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RestError = void 0;
const httpStatus_1 = require("./httpStatus");
class RestError extends Error {
/**
* An Error that will be caught and turned into a JSON rest response.
* @param statusCode the HTTP status code to send (defaults to 500)
* @param message the message for the error (defaults to a description of statusCode)
* @param additionalParams additional properties to put on the JSON response object
*/
constructor(statusCode = httpStatus_1.httpStatusCode.serverError.INTERNAL_SERVER_ERROR, message = httpStatus_1.httpStatusString[statusCode] || statusCode.toString(), additionalParams) {
super(message);
this.statusCode = statusCode;
this.additionalParams = additionalParams;
this.isRestError = true;
if (typeof statusCode !== "number" || statusCode.toString(10).length !== 3 || statusCode < 100 || statusCode > 599) {
throw new Error(`illegal HTTP status code ${statusCode}`);
}
}
}
exports.RestError = RestError;
//# sourceMappingURL=RestError.js.map