question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

401 not handled on iOS

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
screendrivercommented, Mar 21, 2016

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.

1reaction
screendrivercommented, Oct 25, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found