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

Prototype for v19 support #82

Closed
wants to merge 1 commit into from
Closed

Prototype for v19 support #82

wants to merge 1 commit into from

Conversation

jlopezxs
Copy link
Contributor

Resolves #59

@@ -172,13 +172,13 @@ function fixConfig(axios, config) {
*/
export default function axiosRetry(axios, defaultOptions) {
axios.interceptors.request.use(config => {
const currentState = getCurrentState(config);
const currentState = getCurrentState(axios);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this not use a single state per whole axios instance? Will that not make requesting separate resources with the same axios instance impossible, because their retry states will be the same instead of independent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. But it does not cause too much trouble I guess... I personally tend to create as many custom Axios instances as microservices (apis) my app talks to, e.g.:

const todosApiClient = axios.create({ baseURL: 'https://todos-api.com' });
const todosApiClientWithRetry = axiosRetry(todosApiClient, { ... });

const usersApiClient = axios.create({ baseURL: 'https://users-api.com' });
const usersApiWithLogger = axiosLogger(usersApiClient, { ... });

// etc.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While that is true, and it is nice that it works for you, it is certainly not standard and very much unexpected behavior for anyone who reuses axios instance for different MS. Or for example has axios instance for a single domain but the domain is API gateway and so different resources can have vastly different availability.

Right now this change would make safe axios instance reuse impossible.

Keeping retry state in config.adapter as seen in https://github.com/softonic/axios-retry/pull/76/files would not work?

Copy link
Contributor

@mawrkus mawrkus Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API gateway is an interesting use case, we should indeed find a way to support it.
On one side, I'm not super keen to follow the config.adapter approach as we shouldn't modify what we don't own. On the other side, I don't see how we could pass the axios-retry state from one retry to the next in a reliable way...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...unless we decorate Axios request method in order to store the axios-retry state in a local "cache", the cache could be a WeakMap and the key, the config passed to the request method.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WeakMap idea sounds pretty good to me, compatibility with ie < 11 aside. Either with the request object itself as key, as you say, or on some id that is generated in an interceptor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One solution could come from Axios itself axios/axios#2207

@jkelin
Copy link

jkelin commented Jul 10, 2019

Has there been any progress on this?

@ArchangelX360
Copy link

Hey guys, what is preventing this MR to be merged and a new version to be released?

@connecteev
Copy link

can this be merged in?

@polynatic
Copy link

Hey there 👋, if you're waiting for axios/axios#2207 to be released instead, please give a quick update. There is no need to copy their communication habits. :)

@ruscon
Copy link

ruscon commented Oct 31, 2019

I think, if this fix works with axios@latest - push it.

@mawrkus
Copy link
Contributor

mawrkus commented May 26, 2020

Looks like with axios 0.19.1 this PR is not needed anymore.

@mawrkus mawrkus closed this May 26, 2020
@mindhells mindhells deleted the v19-support branch October 13, 2021 17:45
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

Successfully merging this pull request may close these issues.

retries-property not working when using axios v0.19.0-beta.1
7 participants