Refactor findStatusCode for legibility

...disregarding jshint opinion
This commit is contained in:
Javier Goizueta
2016-01-27 17:39:24 +01:00
parent 6dbb0cb1c1
commit 37a4aaeeb4
+4 -1
View File
@@ -239,6 +239,7 @@ module.exports.findStatusCode = findStatusCode;
function statusFromErrorMessage(errMsg) {
// Find an appropriate statusCode based on message
// jshint maxcomplexity:7
var statusCode = 400;
if ( -1 !== errMsg.indexOf('permission denied') ) {
statusCode = 403;
@@ -249,9 +250,11 @@ function statusFromErrorMessage(errMsg) {
else if (errMsg.match(/Postgis Plugin.*[\s|\n].*column.*does not exist/)) {
statusCode = 400;
}
else if ( -1 !== errMsg.indexOf('does not exist') && !errMsg.match(/function .* does not exist/ ) ) {
else if ( -1 !== errMsg.indexOf('does not exist') ) {
if ( -1 !== errMsg.indexOf(' role ') ) {
statusCode = 403; // role 'xxx' does not exist
} else if ( errMsg.match(/function .* does not exist/) ) {
statusCode = 400; // invalid SQL (SQL function does not exist)
} else {
statusCode = 404;
}