diff --git a/CHANGELOG.md b/CHANGELOG.md index 39833df..83c1ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Feature #291: add support for sending 'raw' requests (thanks to jachstet-sea and chuchuva) - Feature #155: add OPTIONS method +- Feature #283: improve error message on timeout on browser platform ## 2.3.1 diff --git a/src/browser/cordova-http-plugin.js b/src/browser/cordova-http-plugin.js index 8b17e9b..fbf3876 100644 --- a/src/browser/cordova-http-plugin.js +++ b/src/browser/cordova-http-plugin.js @@ -171,10 +171,19 @@ function sendRequest(method, withData, opts, success, failure) { xhr.responseType = responseType; setHeaders(xhr, headers); - xhr.onerror = xhr.ontimeout = function () { + xhr.onerror = function () { return failure(createXhrFailureObject(xhr)); }; + xhr.ontimeout = function () { + return failure({ + status: -4, + error: 'Request timed out', + url: url, + headers: {} + }); + }; + xhr.onload = function () { if (xhr.readyState !== xhr.DONE) return;