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.

.catch transformRequest / transformResponse errors

See original GitHub issue

I might be missing something here (saw #61 and #110 related), but…

Looks like there’s no way to .catch in the Promise control flow any error occurring during the transform phase, e.g. here: https://github.com/mzabriskie/axios/blob/master/lib/adapters/xhr.js#L12-L17 you’d need to try {} catch {} transformData() and reject accordingly the Promise

Is this deliberate?

I think It’s ok to have your own error handlers in transformResponse like you say here: https://github.com/mzabriskie/axios/issues/110#issuecomment-142682301 , but what if the user wants to handle errors down the Promise chain? (In my experience this is the expected way of handling errors when dealing with a Promise-based api)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
lingnandcommented, Oct 18, 2016

Can we reopen this issue? I just stumbled upon this as well. Promise-based api should handle all errors as reject or at least provide a mechanism for the user to call reject. With the current api I have to do this

axios({
  transformResponse: [data => {
    try {
      //... data
    } catch(e) {
    }
    return null;
  }]
}).then(resp => {
  if (resp == null) {
    throw new Error('NULL!');
  }
  return resp;
})

Which is not ideal.

0reactions
rubennortecommented, Apr 2, 2017

This was solved after a refactor a few versions ago.

Read more comments on GitHub >

github_iconTop Results From Across the Web

error when try to get data from json angular - Stack Overflow
In your code, $scope.experiences is the promise object and return response.data; is returning to nothing. You need to use the promise object ...
Read more >
axios error bad request | The AI Search Engine You Control
A conventional approach is to catch errors in the catch() block like below: axios.get('/api/xyz/abcd') .catch(function (error) { if (error.response) ...
Read more >
How to Perform HTTP Requests with Axios – A Complete Guide
To obtain the response and catch any errors, we must utilize the then() and ... two config options: transformRequest and transformResponse, ...
Read more >
Axios Cheat Sheet - Kapeli - Dash for macOS
Make a request for a user with a given ID axios.get('/user?ID=12345') .then(function (response) { console.log(response); }) .catch(function (error) ...
Read more >
Post User Registration Action ERROR - Auth0 Community
But using string interpolation always results in an error! ... .catch(err => { console.log(err); console.log('Got here') }); };. Full Error ...
Read more >

github_iconTop Related Medium Post

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