Skip to content

xhr-polyfill setting response status code 400 for remote https calls in airplane mode #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jacobg opened this issue Feb 13, 2020 · 4 comments

Comments

@jacobg
Copy link

jacobg commented Feb 13, 2020

Here is the relevant code:

HttpHandler._error = function (reqContext, error, underlyingErrorCode)
{
var isTimeout = (HttpHandler._UNDERLYING_ERROR_CODES.NSURLErrorTimedOut === underlyingErrorCode);
if (isTimeout)
{
reqContext.status = 0;
reqContext.statusText = reqContext.responseText = null;
}
else
{
reqContext.status = 400;
reqContext.statusText = "Bad Request";
reqContext.responseText = error;

Why does it do that? An application should expect 0 status code for network issues, and defined http status codes such as 400 should be expected to only be what comes back from server.

jacobg added a commit to jacobg/cordova-plugin-wkwebview-file-xhr that referenced this issue Feb 13, 2020
@jacobg
Copy link
Author

jacobg commented Feb 13, 2020

I created a forked repo to resolve this issue:
https://github.com/jacobg/cordova-plugin-wkwebview-file-xhr

It simply changes the HttpHandler._error handler as follows:

  HttpHandler._error = function (reqContext, error, underlyingErrorCode)
  {
    var isTimeout = (HttpHandler._UNDERLYING_ERROR_CODES.NSURLErrorTimedOut === underlyingErrorCode);

    // Set status to -1 instead of the more common 0, because incidentally Ext JS interprets
    // status 0 with a non-empty responseText string as a successful response. It does that,
    // because it thinks it might have been a file:// response. So we'll use -1 instead,
    // because we want the caller to be able to access the error message, and there's
    // really no other property but responseText for that. An alternative would be to
    // rely on an 'error' event, but Ext JS doesn't do that.
    reqContext.status = -1;
    reqContext.statusText = null;
    reqContext.responseText = error;

    reqContext.dispatchReadyStateChangeEvent(2); //HEADERS_RECIEVED
    reqContext.dispatchReadyStateChangeEvent(3); //LOADING
    reqContext.dispatchProgressEvent("progress");
    reqContext.dispatchReadyStateChangeEvent(4); //DONE

    if (isTimeout)
      reqContext.dispatchProgressEvent("timeout");
    else
      reqContext.dispatchProgressEvent("error");

    reqContext.dispatchProgressEvent("loadend");
  };

jacobg added a commit to jacobg/cordova-plugin-wkwebview-file-xhr that referenced this issue Feb 13, 2020
@manish2788
Copy link
Member

@jacobg Will have a look into this issue and get back to you

@mcelkys
Copy link

mcelkys commented Feb 9, 2021

I have the exact same problem. Are there any news with regards to getting this resolved?

@jacobg
Copy link
Author

jacobg commented Feb 9, 2021

With the latest version of cordova ios and better support for wkwebview, I stopped using this plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants