diff --git a/package.json b/package.json index 1b76c140..ed53a871 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "onstarjs", - "version": "2.0.6", + "version": "2.0.7", "description": "Unofficial package for making OnStar API requests", "main": "dist/index.js", "module": "dist/index.esm.js", diff --git a/src/RequestService.ts b/src/RequestService.ts index 4a9c0946..019aab62 100644 --- a/src/RequestService.ts +++ b/src/RequestService.ts @@ -251,11 +251,16 @@ class RequestService { private async refreshAuthToken(): Promise { if (!this.tokenRefreshPromise) { - this.tokenRefreshPromise = new Promise(async resolve => { - const token = await this.createNewAuthToken(); + this.tokenRefreshPromise = new Promise(async (resolve, reject) => { + try { + const token = await this.createNewAuthToken(); + + resolve(token); + } catch (e) { + reject(e); + } this.tokenRefreshPromise = undefined; - resolve(token); }); } @@ -272,16 +277,21 @@ class RequestService { private async connectAndUpgradeAuthToken(): Promise { if (!this.tokenUpgradePromise) { - this.tokenUpgradePromise = new Promise(async resolve => { - await this.connectRequest(); - await this.upgradeRequest(); + this.tokenUpgradePromise = new Promise(async (resolve, reject) => { + try { + await this.connectRequest(); + await this.upgradeRequest(); + + if (this.authToken) { + this.authToken.upgraded = true; + } - if (this.authToken) { - this.authToken.upgraded = true; + resolve(this.authToken); + } catch (e) { + reject(e); } this.tokenUpgradePromise = undefined; - resolve(this.authToken); }); } diff --git a/test/functional.ts b/test/functional.ts index ef8f8897..1ca72d7e 100644 --- a/test/functional.ts +++ b/test/functional.ts @@ -35,7 +35,7 @@ const onStar = OnStar.create(config); ); } } catch (e) { - console.error(e.message); + console.error("Functional Test Error", e.message); if (e.request) { console.error(`Request: ${e.request.path}`);