From 0b79ea32a1ff0fb6587131b817bc1ee137ecd34f Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 08:10:56 +0000 Subject: [PATCH] chore: better object fallback behaviour for casting errors (#260) --- src/core.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core.ts b/src/core.ts index 6b59935..5d652d0 100644 --- a/src/core.ts +++ b/src/core.ts @@ -978,6 +978,11 @@ const validatePositiveInteger = (name: string, n: unknown): number => { export const castToError = (err: any): Error => { if (err instanceof Error) return err; + if (typeof err === 'object' && err !== null) { + try { + return new Error(JSON.stringify(err)); + } catch {} + } return new Error(err); };