@@ -78,7 +78,10 @@ export class BluelinkCanada extends Bluelink {
78
78
expiry : Math . floor ( Date . now ( ) / 1000 ) + resp . json . result . token . expireIn , // we only get a expireIn not a actual date
79
79
}
80
80
}
81
- throw Error ( `Login Failed: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` )
81
+
82
+ const error = `Login Failed: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
83
+ await this . logger . log ( error )
84
+ throw Error ( error )
82
85
}
83
86
84
87
protected async setCar ( id : string ) {
@@ -89,9 +92,9 @@ export class BluelinkCanada extends Bluelink {
89
92
} ) ,
90
93
} )
91
94
if ( ! this . requestResponseValid ( resp . json ) ) {
92
- throw Error (
93
- `Failed to set car ${ id } : ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
94
- )
95
+ const error = `Failed to set car ${ id } : ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
96
+ await this . logger . log ( error )
97
+ throw Error ( error )
95
98
}
96
99
}
97
100
@@ -122,9 +125,9 @@ export class BluelinkCanada extends Bluelink {
122
125
modelTrim : vehicle . trim ,
123
126
}
124
127
}
125
- throw Error (
126
- `Failed to retrieve vehicle list: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
127
- )
128
+ const error = `Failed to retrieve vehicle list: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
129
+ await this . logger . log ( error )
130
+ throw Error ( error )
128
131
}
129
132
130
133
protected returnCarStatus ( status : any , forceUpdate : boolean , odometer ?: number ) : BluelinkStatus {
@@ -199,9 +202,9 @@ export class BluelinkCanada extends Bluelink {
199
202
: this . returnCarStatus ( resp . json . result . status , forceUpdate , resp . json . result . vehicle . odometer )
200
203
}
201
204
202
- throw Error (
203
- `Failed to retrieve vehicle status: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
204
- )
205
+ const error = `Failed to retrieve vehicle status: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
206
+ await this . logger . log ( error )
207
+ throw Error ( error )
205
208
}
206
209
207
210
protected async getAuthCode ( ) : Promise < string > {
@@ -216,9 +219,9 @@ export class BluelinkCanada extends Bluelink {
216
219
if ( this . requestResponseValid ( resp . json ) ) {
217
220
return resp . json . result . pAuth
218
221
}
219
- throw Error (
220
- `Failed to get auth code: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
221
- )
222
+ const error = `Failed to get auth code: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
223
+ await this . logger . log ( error )
224
+ throw Error ( error )
222
225
}
223
226
224
227
protected async pollForCommandCompletion (
@@ -240,9 +243,9 @@ export class BluelinkCanada extends Bluelink {
240
243
} )
241
244
242
245
if ( ! this . requestResponseValid ( resp . json ) ) {
243
- throw Error (
244
- `Failed to poll for command completion: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
245
- )
246
+ const error = `Failed to poll for command completion: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
247
+ await this . logger . log ( error )
248
+ throw Error ( error )
246
249
}
247
250
248
251
if ( resp . json . result . transaction . apiResult === 'C' ) {
@@ -291,9 +294,9 @@ export class BluelinkCanada extends Bluelink {
291
294
const transactionId = resp . resp . headers . transactionId
292
295
return await this . pollForCommandCompletion ( id , authCode , transactionId )
293
296
}
294
- throw Error (
295
- `Failed to send lockUnlock command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
296
- )
297
+ const error = `Failed to send lockUnlock command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
298
+ await this . logger . log ( error )
299
+ throw Error ( error )
297
300
}
298
301
299
302
protected async startCharge ( id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
@@ -325,9 +328,9 @@ export class BluelinkCanada extends Bluelink {
325
328
const transactionId = resp . resp . headers . transactionId
326
329
return await this . pollForCommandCompletion ( id , authCode , transactionId )
327
330
}
328
- throw Error (
329
- `Failed to send charge command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
330
- )
331
+ const error = `Failed to send charge command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
332
+ await this . logger . log ( error )
333
+ throw Error ( error )
331
334
}
332
335
333
336
protected async climateOn ( id : string , config : ClimateRequest ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
@@ -368,9 +371,9 @@ export class BluelinkCanada extends Bluelink {
368
371
const transactionId = resp . resp . headers . transactionId
369
372
return await this . pollForCommandCompletion ( id , authCode , transactionId )
370
373
}
371
- throw Error (
372
- `Failed to send climateOff command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
373
- )
374
+ const error = `Failed to send climateOff command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
375
+ await this . logger . log ( error )
376
+ throw Error ( error )
374
377
}
375
378
376
379
protected async climateOff ( id : string ) : Promise < { isSuccess : boolean ; data : BluelinkStatus } > {
@@ -391,8 +394,8 @@ export class BluelinkCanada extends Bluelink {
391
394
const transactionId = resp . resp . headers . transactionId
392
395
return await this . pollForCommandCompletion ( id , authCode , transactionId )
393
396
}
394
- throw Error (
395
- `Failed to send climateOff command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } ` ,
396
- )
397
+ const error = `Failed to send climateOff command: ${ JSON . stringify ( resp . json ) } request ${ JSON . stringify ( this . debugLastRequest ) } `
398
+ await this . logger . log ( error )
399
+ throw Error ( error )
397
400
}
398
401
}
0 commit comments