Skip to content

Commit

Permalink
feat: emit an Error object upon middleware error
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Oct 30, 2020
1 parent 969debe commit 0939395
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/socket.ts
Expand Up @@ -250,7 +250,10 @@ export class Socket extends Emitter {
break;

case PacketType.CONNECT_ERROR:
super.emit("connect_error", packet.data);
const err = new Error(packet.data.message);
// @ts-ignore
err.data = packet.data.data;
super.emit("connect_error", err);
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/socket.ts
Expand Up @@ -177,7 +177,8 @@ describe("socket", function () {
it("should fire an error event on middleware failure from custom namespace", (done) => {
const socket = io("/no", { forceNew: true });
socket.on("connect_error", (err) => {
expect(err).to.eql("Auth failed (custom namespace)");
expect(err).to.be.an(Error);
expect(err.message).to.eql("Auth failed (custom namespace)");
socket.disconnect();
done();
});
Expand Down

0 comments on commit 0939395

Please sign in to comment.