@evergis/api 4.1.40 → 4.1.42
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/dist/api.esm.js +21 -15
- package/dist/api.esm.js.map +1 -1
- package/dist/index.js +21 -15
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/api.esm.js
CHANGED
|
@@ -2946,23 +2946,29 @@ class Api extends EventEmitter {
|
|
|
2946
2946
|
beforeRetry: [
|
|
2947
2947
|
async ({ request, error, retryCount }) => {
|
|
2948
2948
|
if (error instanceof HTTPError &&
|
|
2949
|
-
error.response.status === 401 &&
|
|
2950
2949
|
retryCount === 1) {
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
refreshToken
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2950
|
+
switch (error.response.status) {
|
|
2951
|
+
case 401:
|
|
2952
|
+
try {
|
|
2953
|
+
const refreshToken = window.localStorage.getItem(STORAGE_REFRESH_TOKEN_KEY);
|
|
2954
|
+
if (refreshToken) {
|
|
2955
|
+
const refreshTokenResponse = await this.account.refreshToken({
|
|
2956
|
+
refreshToken,
|
|
2957
|
+
});
|
|
2958
|
+
if (refreshTokenResponse) {
|
|
2959
|
+
window.localStorage.setItem(STORAGE_TOKEN_KEY, refreshTokenResponse.token);
|
|
2960
|
+
window.localStorage.setItem(STORAGE_REFRESH_TOKEN_KEY, refreshTokenResponse.refreshToken);
|
|
2961
|
+
}
|
|
2962
|
+
request.headers?.set("Authorization", `Bearer ${refreshTokenResponse.token || ""}`);
|
|
2963
|
+
}
|
|
2964
|
+
else {
|
|
2965
|
+
await this.account.logout();
|
|
2966
|
+
}
|
|
2960
2967
|
}
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
throw new Error("Failed to refresh token");
|
|
2968
|
+
catch (error) {
|
|
2969
|
+
await this.account.logout();
|
|
2970
|
+
}
|
|
2971
|
+
break;
|
|
2966
2972
|
}
|
|
2967
2973
|
}
|
|
2968
2974
|
},
|