You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError from fetch module due to no headers received #1737
Bug report
I don't know if you would classify this as a bug, but when a request done via the fetch module returns no headers, it will throw an error here:
Which eventually calls the xhr.onerror handler which is set to always throw:
reject(newTypeError('Network request failed'))
Headers should be set, but when they're not, this is what happens. Which leads me to my question...
Question
I'm completely stumped by this and am by no means implying that this is caused by the fetch/xhr modules, but I'm completely lost on where to look right now. When my remote API endpoint returns with a 401 - Unathorized, the xhr response does not pick up any response headers. If I return a 403 instead, response headers are present.
I've verified that it's not the API server doing something wrong, because the response headers are picked up by numerous other Clients such as Postman, Webbrowser, etc, when I return a 401. Any ideas?
Debugging this on my own by logging the output of the xhr module, I still find no explanation why the headers object was empty to begin with. It makes no sense at all. Even here: https://github.com/NativeScript/NativeScript/blob/master/xhr/xhr.ts#L85
There are no headers set in the response. I got stuck after that and couldn't dig deeper (http.request(..)), so I'll just add this info here in case someone else has any idea.
I'm getting similar error when trying to make post request with fetch module
CLI error prints
TypeError: Network request failed: unexpected expected token < in JSON at position 3
Activity
enchev commentedon Mar 11, 2016
Hey @wubzz,
The null ref exception was fixed immediately (check my pull request) and here is an example how to get the headers:
wubzz commentedon Mar 11, 2016
@enchev Thanks!
Debugging this on my own by logging the output of the
xhrmodule, I still find no explanation why the headers object was empty to begin with. It makes no sense at all. Even here:https://github.com/NativeScript/NativeScript/blob/master/xhr/xhr.ts#L85
There are no headers set in the response. I got stuck after that and couldn't dig deeper (http.request(..)), so I'll just add this info here in case someone else has any idea.
enchev commentedon Mar 12, 2016
Hey @wubzz,
After I've fixed the exception I was able to get headers using http://httpbin.org/status/401 url from the echo service we use for testing.
bismert commentedon Jun 23, 2017
I'm getting similar error when trying to make post request with fetch module
CLI error prints
TypeError: Network request failed: unexpected expected token < in JSON at position 3
lock commentedon Aug 28, 2019
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.