Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to redo a request if failed? #321

Open
extralsc opened this issue Nov 28, 2023 · 0 comments
Open

Is there a way to redo a request if failed? #321

extralsc opened this issue Nov 28, 2023 · 0 comments

Comments

@extralsc
Copy link

Hello,

Basiclly I wounder if there is a way to insert the config of a older request in a new one?

For example:

apiClient.addAsyncResponseTransform(async (response) => {
    console.log("Response after request: ", response);

    const prevRequest = response?.config;

    if (response.data.status == "expiredToken" && response.status === 403 && !prevRequest?.sent) {
        prevRequest.sent = true;

        const newAccessTokenResponse = await apiClient.get("/refresh");
        const newAccessToken = newAccessTokenResponse.data.accessToken;
        
        prevRequest.headers["authorization"] = "Bearer " + newAccessToken;
        
        **--> // MAKE NEW REQUEST HERE WITH SAME CONFIG AS OLD ONE? apiConfig.config(prevRequest) or something?**
    }

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant