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
onRetry and retryInstance not working #107
Comments
When you're saving object to local storage, it needs to be "stringified", which I believe your // ...
try {
await store.dispatch('refreshToken', {
refreshToken: JSON.parse(localStorageService.getRefreshToken()),
});
} catch () { ... }
// ... |
@Flyrell, LocalStorageService in this case is responsible only for accessToken, the problem I described concerns a request that is sent after the function passed as the second parameter. Those, first, a request is sent with a load of 1 image, then a request is sent to receive a fresh token, then a request is sent with a load of 2 images, although it is necessary that the load is from 1 image. That is, a string is placed in the payload of a request that is sent after receiving a fresh token, instead of an object, because of this, the request cannot be processed |
@Flyrell, I was hoping that this problem could be solved by adding an onRetry handler, but the code I indicated above does not work, so I opened this issue. On repeated request, nothing appears in the console, although the onRetry handler is defined |
I see. For some reason I thought the screenshots show the token's content 🤦🏻 Also, tests are showing that the Tests indicate that everything should be working just fine. Would you be able to confirm that no other interceptors are present in your project, that might cause the body to be stringified? The fastest way we can figure out what's going on would be if you can provide a simple reproduction, as it seems like everything is working properly on my site. |
@Flyrell , yeah of course
Its my api client class
I will describe the situation again for full understanding. A request is sent, which responds with a status of 401, after a request is sent to update the token, the response comes, then the first request is repeated, but in the request body, instead of an object, a string with an object is transmitted (as if JSON.stringify). Also, with this scenario and the code above, nothing was displayed in the browser console, although, as I expected, when the request is repeated, the onRetry handler will run and the request config will be displayed in the console. PS: If you need something else to solve this issue, then I am ready to provide everything you need |
I can think of two scenarios where this could be failing.
constructor() {
if (Client.instance) return Client.instance;
// ...
Client.instance = this; // <-- last thing in constructor
}
This is all I can think about for right now, I'm pretty sure it's not an issue in the library itself as I've just tried similar scenario myself on a simple project setup and everything works as expected. Also, make sure the v2.2.8 is installed by looking at |
The issue has been resolved, thanks. Helped point 2 |
Hi, if someone has this problem in the future, check your axios version :), I had that problem and was solved with This was solved in axios v0.21.4 axios/axios#4020 |
I have following code:
Refreshing the token works as expected, but when re-requested, the payload is sent in a wrong(string) format (2 image) instead fine(object) format (1 image). I tried to add a handler to the onRetry parameter but nothing happens.
The text was updated successfully, but these errors were encountered: