Skip to content

Commit

Permalink
Improve exceptionToString
Browse files Browse the repository at this point in the history
  • Loading branch information
schani committed Sep 12, 2024
1 parent 86362e2 commit e887c4b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ export function mapRecordFilterUndefined<T, U>(
*/
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) {
Expand Down

0 comments on commit e887c4b

Please sign in to comment.