From bf814c444242dfdddf2580f9da960224d8efd408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 29 Dec 2017 13:05:01 +0100 Subject: [PATCH] keep error label --- lib/cartodb/controllers/named_maps_admin.js | 23 ++++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 77280015..b46de702 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -24,8 +24,8 @@ NamedMapsAdminController.prototype.register = function (app) { app.base_url_templated + '/', cors(), userMiddleware, - this.checkContentType('POST'), - this.authorizedByAPIKey('create'), + this.checkContentType('POST', 'POST TEMPLATE'), + this.authorizedByAPIKey('create', 'POST TEMPLATE'), this.create.bind(this) ); @@ -33,8 +33,8 @@ NamedMapsAdminController.prototype.register = function (app) { app.base_url_templated + '/:template_id', cors(), userMiddleware, - this.checkContentType('PUT'), - this.authorizedByAPIKey('update'), + this.checkContentType('PUT', 'PUT TEMPLATE'), + this.authorizedByAPIKey('update', 'PUT TEMPLATE'), this.update.bind(this) ); @@ -42,7 +42,7 @@ NamedMapsAdminController.prototype.register = function (app) { app.base_url_templated + '/:template_id', cors(), userMiddleware, - this.authorizedByAPIKey('get'), + this.authorizedByAPIKey('get', 'GET TEMPLATE'), this.retrieve.bind(this) ); @@ -50,7 +50,7 @@ NamedMapsAdminController.prototype.register = function (app) { app.base_url_templated + '/:template_id', cors(), userMiddleware, - this.authorizedByAPIKey('delete'), + this.authorizedByAPIKey('delete', 'DELETE TEMPLATE'), this.destroy.bind(this) ); @@ -58,7 +58,7 @@ NamedMapsAdminController.prototype.register = function (app) { app.base_url_templated + '/', cors(), userMiddleware, - this.authorizedByAPIKey('list'), + this.authorizedByAPIKey('list', 'GET TEMPLATE LIST'), this.list.bind(this) ); @@ -174,7 +174,7 @@ NamedMapsAdminController.prototype.list = function(req, res, next) { ); }; -NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) { +NamedMapsAdminController.prototype.authorizedByAPIKey = function (action, label) { return function authorizedByAPIKeyMiddleware (req, res, next) { const { user } = res.locals; @@ -186,6 +186,7 @@ NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) { if (!authenticated) { const error = new Error(`Only authenticated user can ${action} templated maps`); error.http_status = 403; + error.label = label; return next(error); } @@ -194,10 +195,12 @@ NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) { }.bind(this); }; -NamedMapsAdminController.prototype.checkContentType = function (action) { +NamedMapsAdminController.prototype.checkContentType = function (action, label) { return function checkContentTypeMiddleware (req, res, next) { if (!req.is('application/json')) { - return next(new Error(`template ${action} data must be of type application/json`)); + const error = new Error(`template ${action} data must be of type application/json`); + error.label = label; + return next(error); } next(); };