ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

Set request object on axios errors #264

Open devinpitcher opened 4 years ago

devinpitcher commented 4 years ago

Fixes #168

Adds the request object to the error. This is important and follows the way that Axios handles errors.

marcbachmann commented 3 months ago

I don't think there's an easy way to support that correctly. error.request is the original outgoing request based on the adapter implementation.

require('axios').get('https://example.com/foo').catch((err) => console.error(err.request.url))
> undefined

require('axios').get('https://example.com/foo').catch((err) => console.error(err.request.responseURL))
> undefined

require('axios').get('https://example.com/foo').catch((err) => console.error(err.request.responseUrl))
> undefined

require('axios').get('https://example.com/foo', {adapter: 'fetch'}).catch((err) => console.error(err.request.url))
> 'https://example.com/foo'

responseUrl or responseURL both don't exist at least on node.