Skip to content

Commit

Permalink
chore: better object fallback behaviour for casting errors (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg84 authored and stainless-app[bot] committed Oct 4, 2024
1 parent b7e2113 commit ab12feb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,12 @@ const validatePositiveInteger = (name: string, n: unknown): number => {

export const castToError = (err: any): Error => {
if (err instanceof Error) return err;
return new Error(err);
if (typeof err === 'object' && err !== null) {
try {
return new Error(JSON.stringify(err));
} catch {}
}
return new Error(String(err));
};

export const ensurePresent = <T>(value: T | null | undefined): T => {
Expand Down

0 comments on commit ab12feb

Please sign in to comment.