oracle / cordova-plugin-wkwebview-file-xhr

Cordova Plugin for WebView File XHR
Universal Permissive License v1.0
138 stars 118 forks source link

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

Open jacobg opened 4 years ago

jacobg commented 4 years ago

Here is the relevant code: https://github.com/oracle/cordova-plugin-wkwebview-file-xhr/blob/510de9340187f07c1626c2683101d71ab4637213/src/www/ios/xhr-polyfill.js#L666-L679

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 commented 4 years ago

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");
  };
manish2788 commented 4 years ago

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

mcelkys commented 3 years ago

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

jacobg commented 3 years ago

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