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 + '/',
|
app.base_url_templated + '/',
|
||||||
cors(),
|
cors(),
|
||||||
userMiddleware,
|
userMiddleware,
|
||||||
this.checkContentType('POST'),
|
this.checkContentType('POST', 'POST TEMPLATE'),
|
||||||
this.authorizedByAPIKey('create'),
|
this.authorizedByAPIKey('create', 'POST TEMPLATE'),
|
||||||
this.create.bind(this)
|
this.create.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ NamedMapsAdminController.prototype.register = function (app) {
|
|||||||
app.base_url_templated + '/:template_id',
|
app.base_url_templated + '/:template_id',
|
||||||
cors(),
|
cors(),
|
||||||
userMiddleware,
|
userMiddleware,
|
||||||
this.checkContentType('PUT'),
|
this.checkContentType('PUT', 'PUT TEMPLATE'),
|
||||||
this.authorizedByAPIKey('update'),
|
this.authorizedByAPIKey('update', 'PUT TEMPLATE'),
|
||||||
this.update.bind(this)
|
this.update.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ NamedMapsAdminController.prototype.register = function (app) {
|
|||||||
app.base_url_templated + '/:template_id',
|
app.base_url_templated + '/:template_id',
|
||||||
cors(),
|
cors(),
|
||||||
userMiddleware,
|
userMiddleware,
|
||||||
this.authorizedByAPIKey('get'),
|
this.authorizedByAPIKey('get', 'GET TEMPLATE'),
|
||||||
this.retrieve.bind(this)
|
this.retrieve.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ NamedMapsAdminController.prototype.register = function (app) {
|
|||||||
app.base_url_templated + '/:template_id',
|
app.base_url_templated + '/:template_id',
|
||||||
cors(),
|
cors(),
|
||||||
userMiddleware,
|
userMiddleware,
|
||||||
this.authorizedByAPIKey('delete'),
|
this.authorizedByAPIKey('delete', 'DELETE TEMPLATE'),
|
||||||
this.destroy.bind(this)
|
this.destroy.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ NamedMapsAdminController.prototype.register = function (app) {
|
|||||||
app.base_url_templated + '/',
|
app.base_url_templated + '/',
|
||||||
cors(),
|
cors(),
|
||||||
userMiddleware,
|
userMiddleware,
|
||||||
this.authorizedByAPIKey('list'),
|
this.authorizedByAPIKey('list', 'GET TEMPLATE LIST'),
|
||||||
this.list.bind(this)
|
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) {
|
return function authorizedByAPIKeyMiddleware (req, res, next) {
|
||||||
const { user } = res.locals;
|
const { user } = res.locals;
|
||||||
|
|
||||||
@ -186,6 +186,7 @@ NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) {
|
|||||||
if (!authenticated) {
|
if (!authenticated) {
|
||||||
const error = new Error(`Only authenticated user can ${action} templated maps`);
|
const error = new Error(`Only authenticated user can ${action} templated maps`);
|
||||||
error.http_status = 403;
|
error.http_status = 403;
|
||||||
|
error.label = label;
|
||||||
return next(error);
|
return next(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,10 +195,12 @@ NamedMapsAdminController.prototype.authorizedByAPIKey = function (action) {
|
|||||||
}.bind(this);
|
}.bind(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
NamedMapsAdminController.prototype.checkContentType = function (action) {
|
NamedMapsAdminController.prototype.checkContentType = function (action, label) {
|
||||||
return function checkContentTypeMiddleware (req, res, next) {
|
return function checkContentTypeMiddleware (req, res, next) {
|
||||||
if (!req.is('application/json')) {
|
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();
|
next();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user