2022-02-15 16:17:14 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var http = require('http');
|
|
|
|
|
|
|
|
/* Create an error as per http://bluebirdjs.com/docs/api/catch.html */
|
2022-02-15 16:30:30 -07:00
|
|
|
function StatusError(status, inputMessage) {
|
|
|
|
let message = inputMessage;
|
|
|
|
if (!inputMessage) {
|
2022-02-15 16:17:14 -07:00
|
|
|
message = http.STATUS_CODES[status] || http.STATUS_CODES['500'];
|
|
|
|
}
|
|
|
|
|
2022-09-08 18:15:07 -06:00
|
|
|
this.message = `${status} - ${message}`;
|
2022-09-15 19:41:55 -06:00
|
|
|
// This will be picked by the default Express error handler and assign the status code,
|
|
|
|
// https://expressjs.com/en/guide/error-handling.html#the-default-error-handler
|
2022-02-15 16:17:14 -07:00
|
|
|
this.status = status;
|
|
|
|
this.name = 'StatusError';
|
|
|
|
Error.captureStackTrace(this, StatusError);
|
|
|
|
}
|
|
|
|
StatusError.prototype = Object.create(Error.prototype);
|
|
|
|
StatusError.prototype.constructor = StatusError;
|
|
|
|
|
|
|
|
module.exports = StatusError;
|