Skip to content

Commit 5967e95

Browse files
Merge pull request #108 from simplify9/hamza/fix/infinite-loop-issue
fix: handle 401 error response by retrying the request with a new acc…
2 parents a43ad2c + d7c411c commit 5967e95

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/client/api.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ export const addAxiosInterceptors = (axiosInstance: AxiosInstance, config: AuthC
140140
};
141141
},
142142
async (error: AxiosError) => {
143-
if (error.response.status === 401) {
143+
const originalRequest = error.config as any;
144+
if (error.response.status === 401 && !originalRequest._retry) {
145+
originalRequest._retry = true;
144146
return getAccessToken(accessToken)
145147
.then(newValue => {
146148
accessToken = newValue;
147-
// @ts-ignore
148-
return axiosInstance(error.config);
149+
return axiosInstance(originalRequest);
149150
});
150151
}
151152
if (error.response?.data) {

0 commit comments

Comments
 (0)