Shreya Shah
Shreya Shah

Reputation: 582

Mirage Passthrough returns Response Object instead of JSON data returned from network call

I am getting an error:

Mirage: Your Ember app tried to GET 'http://localhost:3006/data.json', 
but there was no route defined to handle this request. 
Define a route that matches this path in your mirage/config.js file. 
Did you forget to add your namespace?

So following the documentation of mirage i added this:

this.passthrough('http://localhost:3006/data.json');

Even though after adding passthrough, I am getting such Response instead of JSON Object returned from the network api call.

The Actual Request i am making is:

fetch(`${host}/data.json`)
  .then(res => res.json())
  .then(data => {
   // my operation on data
});

The response i am getting is:

{bodyUsed: true
headers: Headers {map: {…}}
ok: true
status: 200
statusText: "OK"
type: "default"
url: "http://localhost:3006/data.json"
_bodyInit: null
_bodyText: ""}

But I am expecting:

 { 
   "files": 
         { 
              "x": "any", 
              "a": "any", 
              "b": "any", 
              "c": "any" 
         } 
 }

I kept a debugger in Pretender.js which is sending the FakeRequest and there in its object, I see that FakeRequest has responseType="" and response as null. And somehow my responseText has value but that is not considered and response value is considered and receiving null.

Also there is a logic which is return saying

"response" in xhr ? xhr.response : xhr.responseText

In this case i have response property but its value is null. Hence according to the above condition it is returning xhr.response which is null

Thanks in Advance.

Upvotes: 1

Views: 1366

Answers (0)

Related Questions