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);
},

View File

@ -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);

View File

@ -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);