Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions modules/services/OsmService.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,7 @@ export class OsmService extends AbstractSystem {
.then(result => gotResult(null, result))
.catch(err => {
if (err.name === 'AbortError') return; // ok
if (err.name === 'FetchError') {
gotResult(err);
return;
}
gotResult(err); // FetchError or network error (e.g. TypeError from connection timeout)
});

return controller;
Expand Down Expand Up @@ -491,10 +488,7 @@ export class OsmService extends AbstractSystem {
.catch(err => {
this._changeset.inflight = null;
if (err.name === 'AbortError') return; // ok
if (err.name === 'FetchError') {
errback(err);
return;
}
errback(err); // FetchError or network error (e.g. TypeError from connection timeout)
});

this._changeset.inflight = controller;
Expand Down Expand Up @@ -541,10 +535,7 @@ export class OsmService extends AbstractSystem {
.catch(err => {
this._changeset.inflight = null;
if (err.name === 'AbortError') return; // ok
if (err.name === 'FetchError') {
errback(err);
return;
}
errback(err); // FetchError or network error (e.g. TypeError from connection timeout)
});

this._changeset.inflight = controller;
Expand Down Expand Up @@ -585,10 +576,7 @@ export class OsmService extends AbstractSystem {
.catch(err => {
this._changeset.inflight = null;
if (err.name === 'AbortError') return; // ok
if (err.name === 'FetchError') {
errback(err);
return;
}
errback(err); // FetchError or network error (e.g. TypeError from connection timeout)
});

this._changeset.inflight = controller;
Expand Down Expand Up @@ -814,7 +802,7 @@ export class OsmService extends AbstractSystem {
const url = this._apiroot + '/api/capabilities.json';
const errback = this._wrapcb(gotResult);

fetch(url)
fetch(url, { signal: AbortSignal.timeout(10000) })
.then(utilFetchResponse)
.then(result => errback(null, result))
.catch(err => errback(err));
Expand Down Expand Up @@ -1125,10 +1113,7 @@ export class OsmService extends AbstractSystem {
.catch(err => {
this._changeset.inflight = null;
if (err.name === 'AbortError') return; // ok
if (err.name === 'FetchError') {
errback(err);
return;
}
errback(err); // FetchError or network error (e.g. TypeError from connection timeout)
});

this._noteCache.inflightPost[note.id] = controller;
Expand Down Expand Up @@ -1198,10 +1183,7 @@ export class OsmService extends AbstractSystem {
.catch(err => {
this._changeset.inflight = null;
if (err.name === 'AbortError') return; // ok
if (err.name === 'FetchError') {
errback(err);
return;
}
errback(err); // FetchError or network error (e.g. TypeError from connection timeout)
});

this._noteCache.inflightPost[note.id] = controller;
Expand Down
22 changes: 22 additions & 0 deletions test/browser/services/OsmService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@ describe('OsmService', () => {
});
});
});


it('calls back with error on network error', done => {
fetchMock.route(/map\.json/, { throws: new TypeError('Failed to fetch') });

_osm.loadFromAPI(path, (err) => {
expect(err).to.be.ok;
expect(err).to.be.instanceof(TypeError);
done();
});
});
});


Expand Down Expand Up @@ -814,6 +825,17 @@ describe('OsmService', () => {
done();
});
});

it('returns error status on network error', done => {
fetchMock.removeRoutes();
fetchMock.route(/api\/capabilities\.json/, { throws: new TypeError('Failed to fetch') });

_osm.status((err, result) => {
expect(err).to.be.ok;
expect(result).to.eql('error');
done();
});
});
});

describe('#imageryBlocklists', () => {
Expand Down