Handle limit errors

This commit is contained in:
rubenmoya 2017-11-07 11:29:42 +01:00
parent c998860ad3
commit e83bcaee6d
3 changed files with 24 additions and 16 deletions

View File

@ -106,7 +106,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
// for each tile shown on the map request the data
this.on('tileAdded', function(t) {
var tileData = this.provider.getTileData(t, t.zoom, function(tileData) {
var successCallback = function (tileData) {
// don't load tiles that are not being shown
if (t.zoom !== self._map.getZoom()) return;
self._tileLoaded(t, tileData);
@ -115,7 +115,12 @@ L.TorqueLayer = L.CanvasLayer.extend({
self.redraw();
}
self.fire('tileLoaded');
});
};
var errorCallback = function (error) {
self.fire('tileError', error);
}
var tileData = this.provider.getTileData(t, t.zoom, successCallback, errorCallback);
}, this);
},
@ -499,7 +504,7 @@ L.TorqueLayer = L.CanvasLayer.extend({
}
return c;
},
invalidate: function() {
this.provider.reload();
},

View File

@ -190,7 +190,7 @@
this.options.cartocss = c;
},*/
setSteps: function(steps, opt) {
setSteps: function(steps, opt) {
opt = opt || {};
if (this.options.steps !== steps) {
this.options.steps = steps;
@ -256,11 +256,11 @@
return null;
},
getTileData: function(coord, zoom, callback) {
getTileData: function(coord, zoom, successCallback, errorCallback) {
if(!this._ready) {
this._tileQueue.push([coord, zoom, callback]);
this._tileQueue.push([coord, zoom, successCallback, errorCallback]);
} else {
this._getTileData(coord, zoom, callback);
this._getTileData(coord, zoom, successCallback, errorCallback);
}
},
@ -281,7 +281,7 @@
* `coord` object like {x : tilex, y: tiley }
* `zoom` quadtree zoom level
*/
_getTileData: function(coord, zoom, callback) {
_getTileData: function(coord, zoom, successCallback, errorCallback) {
var self = this;
var prof_fetch_time = Profiler.metric('torque.provider.windshaft.tile.fetch').start();
var subdomains = this.options.subdomains || '0123';
@ -295,11 +295,14 @@
.replace('{s}', subdomains[index])
var extra = this._extraParams();
torque.net.get( url + (extra ? "?" + extra: ''), function (data) {
torque.net.get( url + (extra ? "?" + extra: ''), function (response) {
prof_fetch_time.end();
if (data && data.responseText) {
var rows = JSON.parse(data.responseText);
callback(self.proccessTile(rows, coord, zoom));
if (response && response.responseText) {
var body = JSON.parse(response.responseText);
response.status === 429
? errorCallback(body.errors_with_context[0])
: successCallback(self.proccessTile(body, coord, zoom));
} else {
Profiler.metric('torque.provider.windshaft.tile.error').inc();
callback(null);
@ -439,7 +442,7 @@
}]
};
}
if(this.options.stat_tag){
allParams["stat_tag"] = this.options.stat_tag;
}

View File

@ -27,9 +27,9 @@ var torque = require('./core');
};
// timeout for errors
var timeoutTimer = setTimeout(function() {
var timeoutTimer = setTimeout(function() {
clean();
callback.call(window, null);
callback.call(window, null);
}, options.timeout);
// setup url
@ -62,7 +62,7 @@ var torque = require('./core');
function respond() {
var status = req.status, result;
var r = options.responseType === 'arraybuffer' ? req.response: req.responseText;
if (!status && r || status >= 200 && status < 300 || status === 304) {
if (!status && r || status >= 200 && status < 300 || status === 304 || status === 429) {
callback(req);
} else {
callback(null);