diff --git a/lib/api/middlewares/authorization.js b/lib/api/middlewares/authorization.js index f998f9362..5d43cff10 100644 --- a/lib/api/middlewares/authorization.js +++ b/lib/api/middlewares/authorization.js @@ -12,6 +12,10 @@ module.exports = function authorization (metadataBackend, forceToBeMaster = fals req.profiler.done('authorization'); return next(new Error('permission denied')); + } else if (!credentials.apiKeyToken) { + req.profiler.done('authorization'); + + return next(new Error('unauthorized')); } res.locals.api_key = credentials.apiKeyToken; diff --git a/lib/services/error-handler.js b/lib/services/error-handler.js index 0d346c6fd..26e7a1ff6 100644 --- a/lib/services/error-handler.js +++ b/lib/services/error-handler.js @@ -32,6 +32,8 @@ class ErrorHandler extends Error { getHttpStatus (httpStatus = 400) { if (this.message.includes('permission denied')) { return 403; + } else if (this.message.includes('unauthorized')) { + return 401; } return httpStatus;