From c85f501f7e19c5313f388f8a2bcaf36cf491fea2 Mon Sep 17 00:00:00 2001 From: shanejonas Date: Thu, 17 Dec 2020 09:05:23 -0800 Subject: [PATCH] fix: jsonrpc error instanceof fixes #209 --- src/Error.test.ts | 5 +++++ src/Error.ts | 1 + 2 files changed, 6 insertions(+) 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 } }