diff --git a/src/Error.test.ts b/src/Error.test.ts index 3531caf..d5e9ae8 100644 --- a/src/Error.test.ts +++ b/src/Error.test.ts @@ -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); + }); + }); diff --git a/src/Error.ts b/src/Error.ts index 2bf30ce..d8d3ae2 100644 --- a/src/Error.ts +++ b/src/Error.ts @@ -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 } }