Description
I have a bit of a weird one and I'm trying to figure it out. I've built on this in a react-native project, they use this polyfill.
I make a JSON request and have a body returned, every other request returns the correct (it's to my own server running a rails app) .json() object, but in this returned object I have the following logs:
Full Response Object:
{ _bodyInit: '{"name":"OURUSER","stateChangedAt":"2016-02-02T06:07:21Z","state":"consumed"}',
_bodyText: '{"name":"OURUSER","stateChangedAt":"2016-02-02T06:07:21Z","state":"consumed"}',
type: 'default',
url: '',
status: 200,
ok: true,
statusText: undefined,
headers:
{ map:
{ 'content-type': [ 'application/json; charset=utf-8' ],
'x-frame-options': [ 'SAMEORIGIN' ],
'x-runtime': [ '0.048328' ],
'x-xss-protection': [ '1; mode=block' ],
server: [ 'nginx' ],
'content-encoding': [ 'gzip' ],
'transfer-encoding': [ 'Identity' ],
'cache-control': [ 'max-age=0, private, must-revalidate' ],
date: [ 'Wed, 03 Feb 2016 05:28:57 GMT' ],
'x-request-id': [ '2e56e87f-87bf-4768-81b1-9b93732d2729' ],
connection: [ 'keep-alive' ],
'x-content-type-options': [ 'nosniff' ],
status: [ '200 OK' ],
vary: [ 'Origin' ] } } }
But if I call data.json()
{ _45: 0, _81: 0, _65: null, _54: null }
But if I call data._bodyText:
{"name":"OURUSER","stateChangedAt":"2016-02-02T06:07:21Z","state":"consumed"}
I've been scratching my head for a few days, I know it's probably a configuration error on a server somewhere but the content types seem to be okay and the headers seem to be okay, I just can't for the life of me figure out what I've done wrong. If this is the wrong project happy to jump down the stack, just haven't seen anyone reporting anything like this before :)
Activity
satya164 commentedon Feb 3, 2016
data.json()
returns aPromise
, so you need to get the resolved value withthen
orawait
. Seems you're directly logging the returnedPromise
.mislav commentedon Feb 3, 2016
Thanks @satya164, you're right. @dannolan: To get either JSON or text representation of the response, you have to use promises:
It's important that you do not use
_bodyText
property. The leading underscore indicates that this property is internal to our polyfill and not part of the fetch API. In fact, your code that users our internal property won't work in browsers that have native fetch implementations, such as Chrome and Firefox.Donhv commentedon Jul 20, 2018
ok thanks