getName refactor

This commit is contained in:
Simon Martín 2018-03-28 12:38:45 +02:00
parent 2bfa00ab57
commit e611d21029
2 changed files with 2 additions and 7 deletions

View File

@ -1,4 +1,5 @@
var PgErrorHandler = require('../postgresql/error_handler');
var pgErrorCodes = require('../postgresql/error_codes');
module.exports = function errorMiddleware() {
return function error(err, req, res, next) {
@ -117,6 +118,6 @@ function createPgError(err) {
err.detail,
err.hint,
err.http_status,
PgErrorHandler.getName(err)
pgErrorCodes.codeToCondition[err.code] || err.name
);
}

View File

@ -1,5 +1,3 @@
var pgErrorCodes = require('./error_codes');
class ErrorHandler extends Error {
constructor(message, context, detail, hint, http_status = 400, name = null) {
super(message);
@ -22,10 +20,6 @@ class ErrorHandler extends Error {
hint: this.hint
};
}
static getName (err) {
return pgErrorCodes.codeToCondition[err.code] || err.name;
}
getHttpStatus (http_status) {
if (this.message.includes('permission denied')) {