You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
751 B
37 lines
751 B
1 year ago
|
'use strict';
|
||
|
|
||
|
class ErrorHandler extends Error {
|
||
|
constructor({ message, context, detail, hint, http_status, name }) {
|
||
|
super(message);
|
||
|
|
||
|
this.http_status = this.getHttpStatus(http_status);
|
||
|
this.context = context;
|
||
|
this.detail = detail;
|
||
|
this.hint = hint;
|
||
|
|
||
|
if (name) {
|
||
|
this.name = name;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
getResponse() {
|
||
|
return {
|
||
|
error: [this.message],
|
||
|
context: this.context,
|
||
|
detail: this.detail,
|
||
|
hint: this.hint
|
||
|
};
|
||
|
}
|
||
|
|
||
|
getHttpStatus(http_status = 400) {
|
||
|
if (this.message.includes('permission denied')) {
|
||
|
return 403;
|
||
|
}
|
||
|
|
||
|
return http_status;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
module.exports = ErrorHandler;
|