CartoDB-SQL-API/lib/services/error-handler.js
Daniel García Aubert 014158c968 Eslint errors
2019-12-26 17:46:27 +01:00

36 lines
749 B
JavaScript

'use strict';
class ErrorHandler extends Error {
constructor ({ message, context, detail, hint, httpStatus, name }) {
super(message);
this.http_status = this.getHttpStatus(httpStatus);
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 (httpStatus = 400) {
if (this.message.includes('permission denied')) {
return 403;
}
return httpStatus;
}
}
module.exports = ErrorHandler;