Skip to content

Commit 56c1985

Browse files
author
Kristian Lyngbaek
committed
Emit an error event when something goes wrong, more closely mirroring the nodejs http module api. This is done my assigning an onerror handler to xhr and propagating the event up.
1 parent c0869e5 commit 56c1985

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/request.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ var Request = module.exports = function (xhr, params) {
3131
true
3232
);
3333

34+
xhr.onerror = function(event) {
35+
self.emit('error', new Error('Network error'));
36+
};
37+
3438
self._headers = {};
3539

3640
if (params.headers) {
@@ -56,6 +60,10 @@ var Request = module.exports = function (xhr, params) {
5660
res.on('ready', function () {
5761
self.emit('response', res);
5862
});
63+
64+
res.on('error', function (err) {
65+
self.emit('error', err);
66+
});
5967

6068
xhr.onreadystatechange = function () {
6169
// Fix for IE9 bug

0 commit comments

Comments
 (0)