Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
MINOR: Fix error message on Datasource connection failure. (#2124)
Browse files Browse the repository at this point in the history
* MINOR: Fix error message on Datasource connection failure.

Caught error might be just a string from a rejected promise.

Signed-off-by: Andres Mandado <andres.mandado-almajano@here.com>

* MINOR: Address review comments.
  • Loading branch information
atomicsulfate committed Feb 26, 2021
1 parent e3a9ec3 commit 1ce7e36
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 4 additions & 1 deletion @here/harp-mapview/lib/MapView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,10 @@ export class MapView extends EventDispatcher {

this.update();
} catch (error) {
logger.error(`Failed to connect to datasource ${dataSource.name}: ${error.message}`);
// error is a string if a promise was rejected.
logger.error(
`Failed to connect to datasource ${dataSource.name}: ${error.message ?? error}`
);

this.m_failedDataSources.add(dataSource.name);
this.dispatchEvent({
Expand Down
4 changes: 3 additions & 1 deletion @here/harp-vectortile-datasource/lib/VectorTileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ export class VectorTileDataSource extends TileDataSource {
try {
await super.connect();
} catch (error) {
// error is a string if the promise was rejected.
if (
error.message &&
WorkerServiceProtocol.isUnknownServiceError(error) &&
!missingOmvDecoderServiceInfoEmitted
) {
Expand All @@ -341,7 +343,7 @@ export class VectorTileDataSource extends TileDataSource {
);
missingOmvDecoderServiceInfoEmitted = true;
}
throw error;
throw typeof error === "string" ? new Error(error) : error;
}
this.configureDecoder(undefined, this.m_decoderOptions);
}
Expand Down
21 changes: 20 additions & 1 deletion @here/harp-vectortile-datasource/test/OmvDataSourceTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { TileKey } from "@here/harp-geoutils";
import { DataProvider } from "@here/harp-mapview-decoder";
import { GeoJsonTiler } from "@here/harp-mapview-decoder/index-worker";
import { silenceLoggingAroundFunction } from "@here/harp-test-utils";
import { assert } from "chai";
import * as chai from "chai";
const { expect, assert } = chai;
// Install chai-as-promised plugin to support promise assertions like:
// expect(promise).to.eventually.be.rejectedWith()
import * as chai_as_promised from "chai-as-promised";
chai.use(chai_as_promised);
import * as sinon from "sinon";

import {
Expand Down Expand Up @@ -211,4 +216,18 @@ describe("DataProviders", function () {

assert.isFalse(markTilesDirty.called);
});

it("connect returns promise rejection as error", function () {
const rejectMsg = "connection failed";
const mockDataProvider = new MockDataProvider();

sinon.stub(mockDataProvider, "connect").callsFake(() => {
return Promise.reject(rejectMsg);
});
const omvDataSource = new VectorTileDataSource({
decoder: new VectorTileDecoder(),
dataProvider: mockDataProvider
});
expect(omvDataSource.connect()).to.eventually.throw("Error", rejectMsg);
});
});

0 comments on commit 1ce7e36

Please sign in to comment.