diff --git a/src/errors/ErrorHandler.ts b/src/errors/ErrorHandler.ts index b02510f..b1bb391 100644 --- a/src/errors/ErrorHandler.ts +++ b/src/errors/ErrorHandler.ts @@ -63,7 +63,10 @@ export class ErrorHandler { longMessage: error.message, }; } - const longMessage = error instanceof Error ? error.message : `${error}`; + if (error instanceof Error) { + return this.#unwrapCause(error); + } + const longMessage = `${error}`; const shortMessage = longMessage.split("\n")[0].slice(0, 128); return { longMessage, @@ -159,6 +162,16 @@ export class ErrorHandler { } } + #unwrapCause(e: Error): Pick { + const shortMessage = e.message.split("\n")[0].slice(0, 128); + let longMessage = e.message; + if (e.cause) { + const cause = this.#unwrapCause(e.cause as Error); + longMessage = longMessage + "Cause: " + cause.longMessage; + } + return { shortMessage, longMessage }; + } + #caLogger(ca?: CreditAccountData): ILogger { return ca ? this.log.child({