Catch "name not found" errors from metadata backend and set http code status 404

This commit is contained in:
Daniel García Aubert 2018-02-19 18:28:58 +01:00
parent 47ccb7ded8
commit 2e3abfb2cd
2 changed files with 22 additions and 9 deletions

View File

@ -70,6 +70,10 @@ AuthApi.prototype.authorizedByAPIKey = function(user, res, callback) {
this.metadataBackend.getApikey(user, apikeyToken, (err, apikey) => { this.metadataBackend.getApikey(user, apikeyToken, (err, apikey) => {
if (err) { if (err) {
if (err.message && -1 !== err.message.indexOf('name not found')) {
err.http_status = 404;
}
return callback(err); return callback(err);
} }

View File

@ -22,6 +22,9 @@ PgConnection.prototype.setDBAuth = function(username, params, apikeyType, callba
if (apikeyType === 'master') { if (apikeyType === 'master') {
this.metadataBackend.getMasterApikey(username, (err, apikey) => { this.metadataBackend.getMasterApikey(username, (err, apikey) => {
if (err) { if (err) {
if (err.message && -1 !== err.message.indexOf('name not found')) {
err.http_status = 404;
}
return callback(err); return callback(err);
} }
@ -39,6 +42,9 @@ PgConnection.prototype.setDBAuth = function(username, params, apikeyType, callba
} else if (apikeyType === 'regular') { //Actually it can be any type of api key } else if (apikeyType === 'regular') { //Actually it can be any type of api key
this.metadataBackend.getApikey(username, params.api_key, (err, apikey) => { this.metadataBackend.getApikey(username, params.api_key, (err, apikey) => {
if (err) { if (err) {
if (err.message && -1 !== err.message.indexOf('name not found')) {
err.http_status = 404;
}
return callback(err); return callback(err);
} }
@ -69,6 +75,9 @@ PgConnection.prototype.setDBAuth = function(username, params, apikeyType, callba
} else if (apikeyType === 'default') { } else if (apikeyType === 'default') {
this.metadataBackend.getApikey(username, 'default_public', (err, apikey) => { this.metadataBackend.getApikey(username, 'default_public', (err, apikey) => {
if (err) { if (err) {
if (err.message && -1 !== err.message.indexOf('name not found')) {
err.http_status = 404;
}
return callback(err); return callback(err);
} }