@eiannone/tesla-api 1.15.1 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/TeslaApi.js +6 -2
- package/package.json +1 -1
package/TeslaApi.js
CHANGED
|
@@ -79,7 +79,7 @@ class TeslaApi {
|
|
|
79
79
|
if (res.statusCode == 401 && this.refresh_token != null) {
|
|
80
80
|
// Tries to refresh the tokens
|
|
81
81
|
this.refreshToken(this.refresh_token)
|
|
82
|
-
.then(_ => this.#apiCall(path, method))
|
|
82
|
+
.then(_ => this.#apiCall(path, method, params))
|
|
83
83
|
.then(response => resolve(response))
|
|
84
84
|
.catch(error => { reject(error); });
|
|
85
85
|
return;
|
|
@@ -175,7 +175,7 @@ class TeslaApi {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
// https://tesla-api.timdorr.com/api-basics/authentication
|
|
178
|
-
async refreshToken(refresh_token) {
|
|
178
|
+
async refreshToken(refresh_token, retry = 1) {
|
|
179
179
|
try {
|
|
180
180
|
const oauth = await this.#oauthCall({
|
|
181
181
|
grant_type: 'refresh_token',
|
|
@@ -191,6 +191,10 @@ class TeslaApi {
|
|
|
191
191
|
return oauth;
|
|
192
192
|
}
|
|
193
193
|
catch(error) {
|
|
194
|
+
if (retry < 3) {
|
|
195
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
196
|
+
return this.refreshToken(refresh_token. retry + 1);
|
|
197
|
+
}
|
|
194
198
|
if (error instanceof Error) error.message += " - Unable to refresh Token";
|
|
195
199
|
throw error;
|
|
196
200
|
}
|