oracle/cordova-plugin-wkwebview-file-xhr

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

jacobg opened this issue · 4 comments

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.

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 Will have a look into this issue and get back to you

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

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