From 2ba7e2df9a28ef9ac49b4a4d0d9ce393bd5ef64c Mon Sep 17 00:00:00 2001 From: Den Williams Date: Mon, 15 Jan 2024 16:52:43 +1100 Subject: [PATCH] fix: error.toString shows object Object --- lib/client.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/client.ts b/lib/client.ts index 9b75f02..f5724e6 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -121,8 +121,9 @@ class RpcResponseError { writable: true, }); + // .message .code .type .expose .instance .type are applied here Object.assign(this, responseBody); - if (!this.source) this.source = []; + this.source = [source, ...(this.source || [])]; Object.defineProperty(this, "stack", { @@ -138,6 +139,12 @@ class RpcResponseError { writable: true, }); } + + toString() { + // defineProperty not recognized by typescript, nor is the result of assign recognizable + const { name, message, instance } = this as any; + return `${name}: ${message} [${instance}]`; + } } export class RPCClient extends BaseClient {