question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AxiosError type for javascript

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:37 (21 by maintainers)

github_iconTop GitHub Comments

3reactions
Khaledgarbayacommented, Aug 20, 2018
3reactions
seanlindocommented, May 3, 2018

This would be wonderful. Running into this issue now!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found