error handling
This commit is contained in:
parent
a5e1681370
commit
fd98a2f102
2 changed files with 25 additions and 10 deletions
13
js/index.js
13
js/index.js
|
|
@ -138,9 +138,18 @@
|
||||||
routing = new BR.Routing({routing: {
|
routing = new BR.Routing({routing: {
|
||||||
router: L.bind(router.getRouteSegment, router)
|
router: L.bind(router.getRouteSegment, router)
|
||||||
}});
|
}});
|
||||||
routing.on('routing:routeWaypointEnd', onUpdate);
|
routing.on('routing:routeWaypointEnd', function(evt) {
|
||||||
|
onUpdate(evt && evt.err);
|
||||||
|
});
|
||||||
|
|
||||||
function onUpdate() {
|
function onUpdate(err) {
|
||||||
|
if (err) {
|
||||||
|
BR.message.showError(err);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
BR.message.hideError();
|
||||||
|
}
|
||||||
|
|
||||||
var track = routing.toPolyline(),
|
var track = routing.toPolyline(),
|
||||||
latLngs = routing.getWaypoints(),
|
latLngs = routing.getWaypoints(),
|
||||||
urls = {};
|
urls = {};
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,16 @@ L.BRouter = L.Class.extend({
|
||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_getError: function(xhr) {
|
||||||
|
var msg = 'no response from server';
|
||||||
|
if (xhr.responseText) {
|
||||||
|
msg = xhr.responseText;
|
||||||
|
} else if (this.status || this.statusText) {
|
||||||
|
msg = this.status + ': ' + this.statusText;
|
||||||
|
}
|
||||||
|
return new Error(msg);
|
||||||
|
},
|
||||||
|
|
||||||
getRoute: function(latLngs, cb) {
|
getRoute: function(latLngs, cb) {
|
||||||
var url = this.getUrl(latLngs),
|
var url = this.getUrl(latLngs),
|
||||||
xhr = new XMLHttpRequest(),
|
xhr = new XMLHttpRequest(),
|
||||||
|
|
@ -67,11 +77,9 @@ L.BRouter = L.Class.extend({
|
||||||
|
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
xhr.onload = L.bind(this._handleRouteResponse, this, xhr, cb);
|
xhr.onload = L.bind(this._handleRouteResponse, this, xhr, cb);
|
||||||
xhr.onerror = function(evt) {
|
xhr.onerror = L.bind(function(xhr, cb) {
|
||||||
// TODO L.Routing._routeSegment doesn't forward err to cb
|
cb(this._getError(xhr));
|
||||||
//cb('Server error');
|
}, this, xhr, cb);
|
||||||
throw 'Server error';
|
|
||||||
};
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -95,9 +103,7 @@ L.BRouter = L.Class.extend({
|
||||||
//gpxLayer.fire('data:loaded');
|
//gpxLayer.fire('data:loaded');
|
||||||
return cb(null, layer);
|
return cb(null, layer);
|
||||||
} else {
|
} else {
|
||||||
// TODO L.Routing._routeSegment doesn't forward err to cb
|
cb(this._getError(xhr));
|
||||||
//cb('Server error');
|
|
||||||
throw 'Server error ' + xhr.responseText || xhr.statusText;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue