axios: AxiosError type for javascript
Summary
Axios rejects error with Error type. Adding custom error type will help with distinguishing between axios and other errors. The only way now is to check ‘request’ field existence which is not always possible. Our internal custom error type has this field too.
Example:
const { axios, AxiosError } = require('axios');
...
try {
...
const response = await axios.get(url);
...
} catch (error) {
if(error instanceof AxiosError) {
return processAxiosError(error);
}
throw error;
}
Context
- axios version: 0.18.0
Relates to: #24
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 13
- Comments: 37 (21 by maintainers)
This is now fixed in https://github.com/axios/axios/pull/1419
This would be wonderful. Running into this issue now!
The PR is already there, I added a soft fix for the 0.x versions as a flag in #1419, and the Error type change for the 1.x in #1420, refer the linked PRs
👋 I’ve been handling all releases for consistency. As soon as CI is green again, I’ll release!
I think if it is implemented, it will be more practical and clearer than using <Error.isAxiosError>.
@nickuraltsev @emilyemorehouse is there a plan releasing this anytime soon?
@axe312ger @Khaledgarbaya is it too soon to request a release please?
That was open source:)
+1