Skip to content

Commit

Permalink
Reject promise on request timeout
Browse files Browse the repository at this point in the history
Firefox and Chrome trigger the request's `onerror` handler when a
timeout occurs. Safari triggers the `ontimeout` handler.

This can be observed by making a request to an unroutable address:

    var xhr = new XMLHttpRequest()
    xhr.onload = console.log.bind(console, 'loaded')
    xhr.onerror = console.log.bind(console, 'errored')
    xhr.ontimeout = console.log.bind(console, 'timeout')
    xhr.open('GET', 'http://10.255.255.1')
    xhr.send()

Fixes #294.
  • Loading branch information
dgraham authored and mislav committed May 5, 2016
1 parent 8deb829 commit 35896c5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@
reject(new TypeError('Network request failed'))
}

xhr.ontimeout = function() {
reject(new TypeError('Network request failed'))
}

xhr.open(request.method, request.url, true)

if (request.credentials === 'include') {
Expand Down

0 comments on commit 35896c5

Please sign in to comment.