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() {
return function error(err, req, res, next) {
if (isTimeoutError(err)) {
pgErrorHandler = createTimeoutError();
} else {
pgErrorHandler = createPgError(err);
}
let pgErrorHandler = getErrorHandler(err);
var msg = pgErrorHandler.getResponse();
@ -90,6 +86,14 @@ function stringifyForLogs(object) {
return JSON.stringify(object);
}
function getErrorHandler (err) {
if (isTimeoutError(err)) {
return createTimeoutError();
} else {
return createPgError(err);
}
}
function isTimeoutError(err) {
return err.message && (
err.message.indexOf('statement timeout') > -1 ||