extracting error type check

This commit is contained in:
Simon Martín 2018-03-28 12:13:31 +02:00
parent 8e5ac72411
commit e2641200f7

View File

@ -3,11 +3,7 @@ var PgErrorHandler = require('../postgresql/error_handler');
module.exports = function errorMiddleware() { module.exports = function errorMiddleware() {
return function error(err, req, res, next) { return function error(err, req, res, next) {
if (isTimeoutError(err)) { let pgErrorHandler = getErrorHandler(err);
pgErrorHandler = createTimeoutError();
} else {
pgErrorHandler = createPgError(err);
}
var msg = pgErrorHandler.getResponse(); var msg = pgErrorHandler.getResponse();
@ -90,6 +86,14 @@ function stringifyForLogs(object) {
return JSON.stringify(object); return JSON.stringify(object);
} }
function getErrorHandler (err) {
if (isTimeoutError(err)) {
return createTimeoutError();
} else {
return createPgError(err);
}
}
function isTimeoutError(err) { function isTimeoutError(err) {
return err.message && ( return err.message && (
err.message.indexOf('statement timeout') > -1 || err.message.indexOf('statement timeout') > -1 ||