Skip to content

Commit

Permalink
fix: jsonrpc error instanceof
Browse files Browse the repository at this point in the history
fixes #209
  • Loading branch information
shanejonas committed Dec 17, 2020
1 parent 7c7c34d commit c85f501
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ describe("Error test", () => {
const err2 = new JSONRPCError("test", 9999, "testdata");
});

it("should be able to use instanceof", () => {
const err = new JSONRPCError("test", 9999);
expect(err instanceof JSONRPCError).toBe(true);
});

});
1 change: 1 addition & 0 deletions src/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class JSONRPCError extends Error {
this.message = message;
this.code = code;
this.data = data;
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain: see https://github.com/open-rpc/client-js/issues/209
}
}

Expand Down

0 comments on commit c85f501

Please sign in to comment.