401 not handled on iOS
See original GitHub issueI am developing an Apache Cordova app and use your polyfill because iOS does not support the fetch API at the moment. Unfortunately this polyfill does not work when the server throws an http 401.
For example I make a fetch POST
request like this one
fetch(address, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
'my': 'body'
}),
})
.then(response => {
if (response.ok) {
return response.json();
}
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
})
On Android I can see the thrown error, on iOS nothing happens. The code block in .then
is never called. It seems that fetch
swallowed everything and does not resolve the promise.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
What is error 401 - Apple Community
That is an HTTP error from a web site which means that the access to to requested resource is not authorized. Check whatever...
Read more >iOS: How can i receive HTTP 401 instead of - Stack Overflow
When NSURLConnection receives the HTTP Code 401, it does not return anything but an error object with code -1012 from the NSURLErrorDomain. - ......
Read more >How to Quickly Fix the 401 Unauthorized Error (5 Methods)
The 401 (Unauthorized) status code indicates that the request has not been applied because it lacks valid authentication credentials for the ...
Read more >401 Unauthorized - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 401 Unauthorized response status code indicates that the client request has not been completed ...
Read more >Resolve errors | Google Drive
Sharing succeeded, but the notification email was not correctly delivered; The ACL change is not allowed for this user. Resolve a 401 error:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, it’s not working. The AJAX request is never returned. In Safari developer tools you can see that the request is never ending. Please reopen this issue.
Hi @zooldk,
as I mentioned before: it is not a bug in this polyfill. It’s a general bug on iOS. You can’t handle http 401 errors from JavaScript on iOS. The only thing you can do is to remove the
WWW-Authenticate
server response header if you have access to the server implementation. Then it should work, but that is a little bit hacky.