From bccd0ed4e0a5a4f3ec53e925d5423313e650bbe3 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 16 May 2022 00:11:53 -0400 Subject: [PATCH] Allow Node command handlers to throw responses and non-Error objects --- node/src/client.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/node/src/client.js b/node/src/client.js index d29791e..b2ff192 100644 --- a/node/src/client.js +++ b/node/src/client.js @@ -1305,15 +1305,22 @@ export default class PeerClient { success: false, status: err.response.status, } + } else if ("status" in err) { + resp.response = err } else { resp.command = "error" + let errorDetails if (err instanceof ProtocolError) { resp.error = err.message - this.error(`Response ${resp.id}: ${err.message}`) - } else { + errorDetails = err.message + } else if (err instanceof Error) { resp.error = err.toString() - this.error(`Response ${resp.id}: ${err.stack}`) + errorDetails = err.stack + } else { + resp.error = JSON.stringify(err) + errorDetails = `throwed ${resp.error}` } + this.error(`Response ${resp.id}: ${errorDetails}`) } } if (resp.response) {