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.

Async await error message?

See original GitHub issue

When using .catch() I get a proper error message with response, stack and message

but when i’m using async/await wrapped in a try/catch I only get config

Example:

 try {
  const { data } = await axios.get(forumUrl)
  resolve(data)
} catch (error) {
  console.log(error) //{config:{...}}
  reject(error)
}

Any idea why?

  • axios version: e.g.: latest

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:51
  • Comments:17

github_iconTop GitHub Comments

38reactions
Vlandmistcommented, Apr 28, 2019

try returning error.response, it worked for me

 try {
  const { data } = await axios.get(forumUrl)
  resolve(data)
} catch (error) {
  console.log(error.response) // <---- 
  reject(error)
}
15reactions
Axnyffcommented, Apr 7, 2018

Hello, Are you using it in the browser or in node? If I do this

try {
  const { data } = await axios.get('http://foo.bar/')
} catch (error) {
  console.log(Object.keys(error), error.message); 
}

I get [“config”, “request”, “response”] “Network Error” so it seems to work properly It seems weird to have something different as async await are just wrapper around promises

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error handling with Async/Await in JS | by Ian Segers | ITNEXT
We can use try...catch for synchronous code. · We can use try...catch (in combination with async functions) and the . · When returning...
Read more >
Async/Await Error Handling - Beginner JavaScript - Wes Bos
We will talk about error handling strategies for async await in this lesson. ... break the entire application if some of the code...
Read more >
Error handling with async/await and promises, n² ... - CatchJS
When dealing with promises, you have no way of knowing if an error will be handled some time in the future. The promise...
Read more >
Async/await - The Modern JavaScript Tutorial
If a promise resolves normally, then await promise returns the result. But in the case of a rejection, it throws the error, just...
Read more >
Async Await Error Handling in JavaScript - The Code Barbarian
When you're first getting started with async/await, it is tempting to use try/catch around every async operation. That's because if you await on ......
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