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