feat #283: improve error message on timeout on browser platform

This commit is contained in:
Sefa Ilkimen 2020-01-27 04:44:13 +01:00
parent 662b4352f5
commit 7193b636f1
No known key found for this signature in database
GPG Key ID: 4AB0B60A9B5E59F5
2 changed files with 11 additions and 1 deletions

View File

@ -4,6 +4,7 @@
- Feature #291: add support for sending 'raw' requests (thanks to jachstet-sea and chuchuva) - Feature #291: add support for sending 'raw' requests (thanks to jachstet-sea and chuchuva)
- Feature #155: add OPTIONS method - Feature #155: add OPTIONS method
- Feature #283: improve error message on timeout on browser platform
## 2.3.1 ## 2.3.1

View File

@ -171,10 +171,19 @@ function sendRequest(method, withData, opts, success, failure) {
xhr.responseType = responseType; xhr.responseType = responseType;
setHeaders(xhr, headers); setHeaders(xhr, headers);
xhr.onerror = xhr.ontimeout = function () { xhr.onerror = function () {
return failure(createXhrFailureObject(xhr)); return failure(createXhrFailureObject(xhr));
}; };
xhr.ontimeout = function () {
return failure({
status: -4,
error: 'Request timed out',
url: url,
headers: {}
});
};
xhr.onload = function () { xhr.onload = function () {
if (xhr.readyState !== xhr.DONE) return; if (xhr.readyState !== xhr.DONE) return;