Closed vbraun closed 6 years ago
It's simulating the same behavior for a native JS XMLHttpRequest. If you went after a resource that was not found or a 500 server except, the XMLHttpRequest fires a "error" event.
Well a 404 doesn't, for example open the console on this page and run:
var xmlhttp = new XMLHttpRequest(),
method = 'GET',
url = 'https://github.com/foo/bar';
xmlhttp.open(method, url, true);
xmlhttp.onerror = function () {
console.log("** An error occurred during the transaction");
};
xmlhttp.send();
does NOT call onerror.
A CORS error will trigger onerror though, i.e. if you run the same snippet from the console on a different website then it will be called.
I see what you mean now. My testbed was a standalone html page loaded from the local file system which would simulate CORS restrictions. Thanks for reporting the issue.
I just pushed in a fix. Please uninstall and re-install the plugin from the master to verify the fix:
cordova plugin remove cordova-plugin-wkwebview-file-xhr cordova plugin add https://github.com/oracle/cordova-plugin-wkwebview-file-xhr.git
The onerror callback should only be called on network-level errors; If there is a response then, by definition, there was no network level error. The value of the status code is irrelevant. More discussion is at https://stackoverflow.com/questions/10584318/when-should-xmlhttprequests-onerror-handler-fire
For the record, angularjs registers an onerror handler that correctly discards any results. So all $http calls that return a statusCode >= 400 now look like network errors.