This is part bug report, and part question.
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:
https://github.com/NativeScript/NativeScript/blob/master/xhr/xhr.ts#L119
Due to the returnvalue here:
https://github.com/NativeScript/NativeScript/blob/master/xhr/xhr.ts#L184
(toLowerCase on null)
Which eventually calls the xhr.onerror handler which is set to always throw:
reject(new TypeError('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?
Running all this on Android.
JS: Response {
JS: "content": {
JS: .......
JS: },
JS: "statusCode": 401,
JS: "headers": {}
JS: }
JS: Response {
JS: "content": {
JS: .......
JS: },
JS: "statusCode": 403,
JS: "headers": {
JS: "Date": "Thu, 10 Mar 2016 14:32:10 GMT",
JS: "Content-Type": "application/json; charset=utf-8",
JS: "Content-Length": "286",
JS: "Keep-Alive": "timeout=15, max=100",
JS: "Connection": "Keep-Alive",
JS: "X-Android-Sent-Millis": "1457620330281",
JS: "X-Android-Received-Millis": "1457620330364"
JS: }
JS: }
This is part bug report, and part question.
Bug report
I don't know if you would classify this as a bug, but when a request done via the
fetchmodule returns no headers, it will throw an error here:https://github.com/NativeScript/NativeScript/blob/master/xhr/xhr.ts#L119
Due to the returnvalue here:
https://github.com/NativeScript/NativeScript/blob/master/xhr/xhr.ts#L184
(toLowerCase on null)
Which eventually calls the
xhr.onerrorhandler which is set to always throw: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?Running all this on Android.