From e887c4bc4ccdb17aac36ed9c48b5fcd87fe579b5 Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Thu, 12 Sep 2024 15:46:37 -0400 Subject: [PATCH] Improve `exceptionToString` --- package.json | 2 +- src/index.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4a2f284..c9bc7be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@glideapps/ts-necessities", - "version": "2.3.0", + "version": "2.3.1", "description": "Small utilities to make life with TypeScript easier", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 127542b..c2bd48d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -195,6 +195,9 @@ export function mapRecordFilterUndefined( */ export function exceptionToString(e: unknown): string { if (e === undefined) return ""; + if (hasOwnProperty(e, "message") && typeof e.message === "string") { + return e.message; + } try { return (e as any).toString(); } catch (f: unknown) {