-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reject request on XHR timeout #2581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,13 @@ module.exports = function($window, Promise, oncompletion) { | |
} | ||
} | ||
|
||
xhr.ontimeout = function (ev) { | ||
if (aborted) return; | ||
var error = new Error("Request timeout"); | ||
error.timeout = ev.target.timeout; | ||
reject(error); | ||
} | ||
Comment on lines
+158
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you verified the |
||
|
||
if (typeof args.config === "function") { | ||
xhr = args.config(xhr, args, url) || xhr | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ o.spec("request", function() { | |
o("works via GET", function(done) { | ||
mock.$defineRoutes({ | ||
"GET /item": function() { | ||
return {status: 200, responseText: JSON.stringify({a: 1})} | ||
return new Promise(function (resolve) { | ||
resolve({status: 200, responseText: JSON.stringify({a: 1})}) | ||
}) | ||
Comment on lines
+21
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this. |
||
} | ||
}) | ||
request({method: "GET", url: "/item"}).then(function(data) { | ||
|
@@ -694,7 +696,9 @@ o.spec("request", function() { | |
o("rejects on error in extract", function(done) { | ||
mock.$defineRoutes({ | ||
"GET /item": function() { | ||
return {status: 200, responseText: JSON.stringify({a: 1})} | ||
return new Promise(function (resolve) { | ||
resolve({status: 200, responseText: JSON.stringify({a: 1})}) | ||
}) | ||
Comment on lines
+699
to
+701
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this. |
||
} | ||
}) | ||
request({ | ||
|
@@ -707,6 +711,30 @@ o.spec("request", function() { | |
done() | ||
}) | ||
}) | ||
o("rejects on timeout", function(done) { | ||
var timeout = 50 | ||
var gotTimeoutError = false | ||
mock.$defineRoutes({ | ||
"GET /item": function() { | ||
return new Promise(function (resolve) { | ||
setTimeout(function () { | ||
resolve({status: 200, responseText: JSON.stringify({a: 1})}) | ||
}, timeout*2) | ||
}) | ||
} | ||
}) | ||
request( | ||
{method: "GET", url: "/item", timeout: timeout} | ||
).catch(function(e) { | ||
gotTimeoutError = true | ||
o(e instanceof Error).equals(true) | ||
o(e.message).equals("Request timeout") | ||
o(e.timeout).equals(timeout) | ||
}).then(function () { | ||
o(gotTimeoutError).equals(true) | ||
done() | ||
}) | ||
}) | ||
}) | ||
o.spec("json header", function() { | ||
function checkUnset(method) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be a little clearer on the error message