AxiosError type for javascript
See original GitHub issueSummary
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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:37 (21 by maintainers)
Top Results From Across the Web
How to type axios error in Typescript? · Issue #3612 - GitHub
Describe the issue I have question how type axios error in Typescript. ... Node.js Version [e.g. 13.0.1]; OS: [e.g. iOS 12.1.0, OSX 10.13.4] ......
Read more >axios Error typescript, annotation must be 'any' or 'unknown' if?
You cannot write a specific annotation for the catch clause variable in typescript, this is because in javascript a catch clause will catch...
Read more >TypeScript: axios, Error Handling - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js. DashboardCtrl+Escape ...
Read more >axios.AxiosError JavaScript and Node.js code examples
The ultimate javascript content-type utility. axios. Promise based HTTP client for the browser and node.js. From CI to AI: The AI layer in...
Read more >Handling Errors | Axios Docs
Handling Errors. axios.get('/user/12345') .catch(function (error) { if (error.response) { // The request was made and the server responded with a status ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is now fixed in https://github.com/axios/axios/pull/1419
This would be wonderful. Running into this issue now!