Do not cache map template CRUD errors in Named Map provider

This commit is contained in:
Daniel García Aubert 2019-09-12 17:23:19 +02:00
parent 0297e09c17
commit 64b4efef17

View File

@ -48,7 +48,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
this.affectedTablesCache = affectedTablesCache;
// providing
this.err = null;
this.mapConfig = null;
this.rendererParams = null;
this.context = {};
@ -56,13 +55,12 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
}
getMapConfig (callback) {
if (!!this.err || this.mapConfig !== null) {
return callback(this.err, this.mapConfig, this.rendererParams, this.context);
if (this.mapConfig !== null) {
return callback(null, this.mapConfig, this.rendererParams, this.context);
}
this.getContext((err, context) => {
if (err) {
this.err = err;
return callback(err);
}
@ -75,8 +73,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
this.config;
} catch (e) {
const err = new Error('malformed config parameter, should be a valid JSON');
this.err = err;
return callback(err);
}
}
@ -85,7 +81,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
this.getTemplate((err, template) => {
if (err) {
this.err = err;
return callback(err);
}
@ -94,7 +89,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
try {
requestMapConfig = this.templateMaps.instance(template, templateParams);
} catch (err) {
this.err = err;
return callback(err);
}
@ -103,7 +97,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
this.mapConfigAdapter.getMapConfig(
user, requestMapConfig, rendererParams, context, (err, mapConfig, stats = {}) => {
if (err) {
this.err = err;
return callback(err);
}
@ -148,7 +141,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
this.userLimitsBackend.getRenderLimits(this.user, this.params.api_key, (err, renderLimits) => {
if (err) {
this.err = err;
return callback(err);
}
@ -163,13 +155,12 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
}
getTemplate (callback) {
if (!!this.err || this.template !== null) {
return callback(this.err, this.template);
if (this.template !== null) {
return callback(null, this.template);
}
this.templateMaps.getTemplate(this.user, this.templateName, (err, tpl) => {
if (err) {
this.err = err;
return callback(err);
}
@ -177,8 +168,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
const error = new Error(`Template '${this.templateName}' of user '${this.user}' not found`);
error.http_status = 404;
this.err = error;
return callback(error);
}
@ -190,15 +179,12 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
const error = new Error('Failed to authorize template');
error.http_status = 403;
this.err = error;
return callback(error);
}
if (!authorized) {
const error = new Error('Unauthorized template instantiation');
error.http_status = 403;
this.err = error;
return callback(error);
}
@ -222,7 +208,6 @@ module.exports = class NamedMapMapConfigProvider extends BaseMapConfigProvider {
this.affectedTables = null;
this.err = null;
this.mapConfig = null;
this.cacheBuster = Date.now();