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.

Request object is not defined on response

See original GitHub issue
const axiosMock = new MockAdapter(axios);
axiosMock.onGet(`${gl.TEST_HOST}/test`).reply(200, { some: 'data' });

axios.get(`${gl.TEST_HOST}/test`)
  .then(response => console.log(response.request));

will result in undefined.

This makes it impossible to test code which handles multiple routes and checks for the incoming request.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
b4handcommented, Jan 30, 2018

Also, the networkError() and timeout() methods don’t include the request object in the resulting Error object. I have some error handling code that inspects the request, but can’t test the error handlers with the mocks enabled.

0reactions
franciscop-sccommented, May 17, 2019

I had a similar issue, and I’ve fixed it for my tests by adding an extra Interceptor to Axios as a workaround:

axios.interceptors.response.use(res => ({ ...res, request: res.request || res.config }));

This will define a request in the main response, so any code that is in the axios.get().then(...) will have the request defined and the same as config 🎉

It will “polyfill” the .request if it doesn’t find it with the config, so feel free to put it wherever you want (though I’d recommend to put it in your tests or test setup).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Response object is not defined when passed in a function
The issue is that response object passed from express route is not defined in get_user_statuses function. Now I have two question:.
Read more >
Why is response not defined? (Example) - Treehouse
Why is response not defined? I am running node app.js, but I keep getting an error: ReferenceError: response is not defined ...
Read more >
fetch() - Web APIs | MDN
The global fetch() method starts the process of fetching a resource from the network, returning a promise which is fulfilled once the response...
Read more >
TypeError: response.json is not a function in JavaScript
The "response.json is not a function" error occurs when we call the json() method on an object that is not the Response object...
Read more >
urllib.request — Extensible library for opening URLs — Python ...
Source code: Lib/urllib/request.py The urllib.request module defines functions and classes ... this function returns a urllib.response.addinfourl object.
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