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.

Catching Axios Result is Undefined

See original GitHub issue

Describe the issue Having an issue which I don’t know if I’m trying to use axios wrong or not but it looks like I’ve got the same syntax as shown in documentation. When using axios.get() I’ll get the result I’m looking for.

I’m calling IActionResult controller endpoints using axios and I’m intentionally returning BadRequest("Test Message"); to see if I can send back any message I want. With the code below I catch the error but the variable err is undefined when using axios.post(). I do the same thing below with axios.get() and I’m catching the error which does get populated correctly. Does this same thing not happen with axios.post()?

If I look in dev tools and view the errored network call I can see my returned message in the response so it is getting sent back. But It doesn’t seem to be getting picked up when catching it.

Example Code

axios
            .post('/Form/SavePersonData', _this.donation)
            .then(function(res) {
            })
            .catch(function(err) {
              alert(err);
              console.log(err);
            });

Environment:

  • Axios Version [e.g. 0.18.0]
  • OS: [e.g. iOS 12.1.0, OSX 10.13.4]
  • Browser [e.g. Chrome, Safari]
  • Browser Version [e.g. 22]
  • Additional Library Versions [e.g. React 16.7, React Native 0.58.0]

Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
varnit03commented, Apr 12, 2019

Reject the axios promise in axios interceptors using Promise.reject(error.response).

0reactions
chinesedfancommented, Dec 5, 2019

@DanJ210 I am not familiar with IActionResult controller endpoints. But did you support POST method in the server side? Anyway, we suggest users ask similar questions in stackoverflow, instead of Github issues. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error.response is undefined if axios request fails
If I add this code to 'main.js' in my app, 'handleApiFail' is called when a request fails, but error.response is undefined in the...
Read more >
How to use the axios.request function in axios - Snyk
To help you get started, we've selected a few axios.request examples, ... await axios.request(reqOptions); result = response.data; } catch (e) { const ...
Read more >
React - axios.get is returning undefined - 404 - Reddit
I'm trying to create an account - which gets saved to my database - and pull that account to the "thank-you" page.
Read more >
[SOLVED] How to return the result of an axios call to the client?
I have an axios get request server side that works as the result is displayed ... to get the result client-side which is...
Read more >
Vue Axios response undefined error - Laracasts
axios .post('/auth/login', {username: username, password: pass}, ).then(function (response) { console.log(response); }).catch(function (error) ...
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