Skip to content

Commit

Permalink
net: Add support for xhr.onerror
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Jul 5, 2024
1 parent 2c25c1b commit af056a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ XMLHttpRequest.prototype = {
result[entrie[0]] = entrie[1]
return result
}, {})
require(url.protocol.slice(0, -1)).request(url, function(res) {
var req = require(url.protocol.slice(0, -1)).request(url, function(res) {
head(res.statusCode, res.statusMessage, res.headers)
res.on("data", fillBody)
res.on("end", done)
}).end(data)
})
if (xhr.onerror) req.on("error", xhr.onerror)
req.end(data)
return
}
if (url.protocol === "data:") {
Expand Down
14 changes: 14 additions & 0 deletions test/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ describe("XMLHttpRequest", function() {
xhr.send()
})

it("calls onerror", function (assert, mock) {
assert.setTimeout(5000)
var xhr = new XMLHttpRequest()
xhr.open("GET", "http://0.0.0.0:0")
xhr.onerror = function() {
assert.equal(xhr.status, 0)
assert.equal(xhr.statusText, "")
assert.equal(xhr.responseXML, null)
assert.equal(xhr.responseText, "")
assert.end()
}
xhr.send()
})

describe("Data URLs", function() {
var table = [
[ "data:,Hello%2C%20World%21", "text/plain", "Hello, World!" ],
Expand Down

0 comments on commit af056a7

Please sign in to comment.