From 8e3cf0a51da57ef41d02a8f01f6fb337bb7387dc Mon Sep 17 00:00:00 2001 From: bgrgicak Date: Thu, 28 Mar 2024 09:18:30 +0100 Subject: [PATCH] Ensure PromiseRejectionEvent has reason before logging it --- packages/php-wasm/logger/src/lib/logger.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/php-wasm/logger/src/lib/logger.ts b/packages/php-wasm/logger/src/lib/logger.ts index 1757f69891..9597691a44 100644 --- a/packages/php-wasm/logger/src/lib/logger.ts +++ b/packages/php-wasm/logger/src/lib/logger.ts @@ -76,7 +76,12 @@ export class Logger extends EventTarget { * @param PromiseRejectionEvent event */ private logUnhandledRejection(event: PromiseRejectionEvent) { - this.log(`${event.reason.stack}`, 'Error'); + // No reason was provided, so we can't log anything. + if (!event?.reason) { + return; + } + const message = event?.reason.stack ?? event.reason; + this.log(message, 'Error'); } /**