Apply asset fallback to database timeout errors

This commit is contained in:
Daniel García Aubert 2017-08-01 12:52:34 +02:00
parent 7d13603163
commit 4c3e3005aa

View File

@ -118,8 +118,27 @@ module.exports = function(serverOptions) {
var onTileErrorStrategy;
if (global.environment.enabledFeatures.onTileErrorStrategy !== false) {
onTileErrorStrategy = function onTileErrorStrategy$TimeoutTile(err, tile, headers, stats, format, callback) {
if (err && err.message === 'Render timed out' && format === 'png') {
return callback(null, timeoutErrorTile, { 'Content-Type': 'image/png' }, {});
function isRenderTimeoutError (err) {
return err.message && (-1 !== err.message.indexOf('Render timed out'));
}
function isDatasourceTimeoutError (err) {
return err.message && (-1 !== err.message.indexOf('canceling statement due to statement timeout'));
}
function isTimeoutError (err) {
return isRenderTimeoutError(err) || isDatasourceTimeoutError(err);
}
function isRasterFormat (format) {
return format === 'png' || format === 'jpg'
}
if (isTimeoutError(err) && isRasterFormat(format)) {
return callback(null, timeoutErrorTile, {
'Content-Type': 'image/png',
}, {});
} else {
return callback(err, tile, headers, stats);
}