@bunnyapp/api-client 1.0.11 → 1.0.12
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/package.json +1 -1
- package/src/index.js +4 -2
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -9,11 +9,13 @@ class Bunny {
|
|
|
9
9
|
assert(options.baseUrl, "Bunny base url required");
|
|
10
10
|
|
|
11
11
|
this.options = options;
|
|
12
|
+
this.retryEnabled = false;
|
|
12
13
|
|
|
13
14
|
if (options.accessToken == undefined) {
|
|
14
15
|
assert(options.clientId, "Bunny API clientId required");
|
|
15
16
|
assert(options.clientSecret, "Bunny API clientSecret required");
|
|
16
17
|
assert(options.scope, "Bunny API scope required");
|
|
18
|
+
this.retryEnabled = true;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
this.client = axios.create({
|
|
@@ -25,6 +27,7 @@ class Bunny {
|
|
|
25
27
|
|
|
26
28
|
this.client.interceptors.response.use(null, async (error) => {
|
|
27
29
|
if (
|
|
30
|
+
this.retryEnabled &&
|
|
28
31
|
error.config &&
|
|
29
32
|
error.response &&
|
|
30
33
|
error.response.status === 401 &&
|
|
@@ -32,14 +35,13 @@ class Bunny {
|
|
|
32
35
|
error.config.url != "/oauth/token"
|
|
33
36
|
) {
|
|
34
37
|
const accessToken = await this.fetchAccessToken();
|
|
35
|
-
|
|
36
38
|
error.config.retry = true;
|
|
37
39
|
error.config.headers["Authorization"] = `bearer ${accessToken}`;
|
|
38
40
|
|
|
39
41
|
return axios.request(error.config);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
return Promise.reject(
|
|
44
|
+
return Promise.reject("Invalid access token");
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
this.webhooks = new Webhooks(options.webhookSigningToken);
|