Closed command-tab closed 8 years ago
The body
on a request is a readable byte stream that should only be consumable once anyway. Do you still see res.json()
returning empty results if you comment out the console.log(res.body)
line?
Hi @taion, thanks for responding so quickly :)
Even when I log only res.json()
, I still get {}
. Is there any way I can dig deeper into what's happening under the hood?
Thanks!
res.json()
actually returns a promise - you'd have to do e.g. res.json().then(json => console.log(json))
.
Aha! That worked — that successfully logged out the data I'm expecting. Hmm, so maybe the API calls are working correctly, and the fact that my Marty container's failed
method is being called is the result of something else.
Interesting... If I dig into the errors
passed to the failed
Marty container method, I see...
{"things":{"name":"Not found","message":"Not found","status":404}}
...despite the fact that my API method is returning 200 OK, with data, as application/json
.
The process for a fetch is:
So presumably your issue that the local handler is still returning undefined even after the remote API call completes. Obvious causes:
I'd suggest looking at your store's state after the failure. Is the remote data actually in the store?
OH, that's totally it!
I was intentionally returning undefined from my locally
handler to force invocation of the remotely
handler, with the thinking that I would get remote data working first, then worry about storing it, then get it to my component. Turns out, Marty is smarter than I assumed it was.
This is great! Thanks @codyhatch and @taion!
Hi folks,
I'm using Marty 0.10.4, and I'm attempting to follow the recommendations for removing dependence on the automatic
parseJSON
call, but I'm seeing a strange behavior: When my valid data source requests finish with 200 OK, callingres.json()
returns an empty object{}
.I'm calling
Marty.HttpStateSource.removeHook('parseJSON');
in myserver.js
to remove the automaticparseJSON
hook, then in my data source, doing a simple GET:If I temporarily omit the removal of the
parseJSON
hook,res.body
is in fact the JSON text that I expect to parse by callingres.json()
, so I can see that my requests are succeeding. I just can't figure out why, in either case,res.json()
always just returns{}
.Am I missing something?
Thanks so much!