keep error label
This commit is contained in:
parent
f136993c50
commit
bf814c4442
@ -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();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user