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

Fixing isAxiosError typings to take generics #3816

Closed
wants to merge 2 commits into from

Conversation

latipun7
Copy link

@latipun7 latipun7 commented May 27, 2021

I'm trying to solve this issue from #3815, this removes a workaround as stated from this #3815 (comment)

Also, I make formatting changes. If you don't like it, I could drop it.

closes: #3815

@latipun7 latipun7 force-pushed the patch-1 branch 2 times, most recently from 0c20e9b to 5f70b1d Compare May 27, 2021 06:07
@Guuz
Copy link

Guuz commented Oct 1, 2021

Whats the status on this?

@latipun7 latipun7 force-pushed the patch-1 branch 2 times, most recently from 12fff93 to 465a617 Compare October 1, 2021 12:50
@latipun7
Copy link
Author

latipun7 commented Oct 1, 2021

Whats the status on this?

I don't know. I already keep this pull sync with master branch. Need maintainer attention to approve this.

Sorry for ping @mzabriskie , @jasonsaayman 🙏

@latipun7
Copy link
Author

bumped.

@jasonsaayman , please give review. I also edit some formatting. If you don't like it, I can revert the format, and update the commit.
Thank you.

@arfianadam
Copy link

This would be very useful. Bumping.

@justirva09
Copy link

waiting for this merge 👍🏻

@jasonsaayman
Copy link
Member

This will have to go into Axios next as it will be a breaking change

@latipun7
Copy link
Author

This will have to go into Axios next as it will be a breaking change

@jasonsaayman sorry if I'm wrong, I don't think this is breaking change, this is just kind of new feature since old behavior still acceptable without issue. This is still good:

let user: User = null;
try {
  const { data } = await axios.get('/user?ID=12345');
  user = data.userDetails;
} catch (error) {
  if (axios.isAxiosError(error)) {
    handleAxiosError(error);
  } else {
    handleUnexpectedError(error);
  }
}

but accept the custom interface:

interface ResponseData {
 // ...
};

interface RequestConfigData {
 // ...
};

let user: User = null;
try {
  const { data } = await axios.get('/user?ID=12345');
  user = data.userDetails;
} catch (error) {
  if (axios.isAxiosError<ResponseData, RequestConfigData>(error)) {
    handleAxiosError(error);
  } else {
    handleUnexpectedError(error);
  }
}

CMIIW

@arthurfiorette
Copy link
Contributor

Why this is a breaking change? All generics have a default any type.

@jasonsaayman
Copy link
Member

This has already fixed with new error handeling

@arfianadam
Copy link

@jasonsaayman what is the new error handling and how does it solve this problem?

@jasonsaayman
Copy link
Member

I have already re-opened one of the other pull requests that deals with this.

@jasonsaayman
Copy link
Member

Closing in favour of #4344

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.

Didn't take Generics in isAxiosError() for AxiosError<any>
6 participants