Skip to content

Commit

Permalink
Pass error from requests in Node to callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Acconut committed Sep 15, 2016
1 parent 5a60939 commit e7a07af
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib.es5/node/request.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/node/request.js
Expand Up @@ -49,8 +49,8 @@ class Request {
this.onload();
});

req.on("error", () => {
this.onerror();
req.on("error", (err) => {
this.onerror(err);
});

if (body instanceof Readable) {
Expand Down
4 changes: 4 additions & 0 deletions test/spec/helpers/node/ajax.js
Expand Up @@ -48,6 +48,10 @@ class MockRequest {
this._req.emit("response", res);
}

responseError(err) {
this._req.emit("error", err);
}

contentType() {
return this.requestHeaders["Content-Type"] || "";
}
Expand Down
24 changes: 24 additions & 0 deletions test/spec/upload.node.js
Expand Up @@ -82,6 +82,30 @@ describe("tus", function () {

expectHelloWorldUpload(file, options, done);
});

it("should pass through errors from the request", function () {
var resErr = new Error("something bad, really!");
var buffer = new Buffer("hello world");
var option = {
endpoint: "/uploads",
onError: function (err) {
expect(err.causingError).toBe(resErr);
}
};

spyOn(option, "onError").and.callThrough();

var upload = new tus.Upload(buffer, option);
upload.start();

var req = jasmine.Ajax.requests.mostRecent();
expect(req.url).toBe("/uploads");
expect(req.method).toBe("POST");

req.responseError(resErr);

expect(option.onError).toHaveBeenCalled();
});
});
});

Expand Down

0 comments on commit e7a07af

Please sign in to comment.