refactoring: use Util.getError

This commit is contained in:
Norbert Renner 2015-03-25 11:30:38 +01:00
parent c3b07eb576
commit 5a10a3a8f7

View file

@ -69,16 +69,6 @@ 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();
@ -90,7 +80,7 @@ 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 = L.bind(function(xhr, cb) { xhr.onerror = L.bind(function(xhr, cb) {
cb(this._getError(xhr)); cb(BR.Util.getError(xhr));
}, this, xhr, cb); }, this, xhr, cb);
xhr.send(); xhr.send();
}, },
@ -112,7 +102,7 @@ L.BRouter = L.Class.extend({
return cb(null, layer); return cb(null, layer);
} else { } else {
cb(this._getError(xhr)); cb(BR.Util.getError(xhr));
} }
}, },