Skip to content

Commit

Permalink
fix: unwrap errors and causes
Browse files Browse the repository at this point in the history
  • Loading branch information
doomsower committed Dec 25, 2024
1 parent 2e5c451 commit 46a61dc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/errors/ErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -159,6 +162,16 @@ export class ErrorHandler {
}
}

#unwrapCause(e: Error): Pick<ExplainedError, "longMessage" | "shortMessage"> {
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({
Expand Down

0 comments on commit 46a61dc

Please sign in to comment.