File tree Expand file tree Collapse file tree 2 files changed +21
-20
lines changed
Expand file tree Collapse file tree 2 files changed +21
-20
lines changed Original file line number Diff line number Diff line change 33 */
44import type { ConsoleLogEvent } from '@hawk.so/types' ;
55import Sanitizer from '../modules/sanitizer' ;
6+ import { stringifyRejectionReason } from 'src/utils/event' ;
67
78/**
89 * Maximum number of console logs to store
@@ -189,25 +190,6 @@ export class ConsoleCatcher {
189190 this . consoleOutput . push ( logEvent ) ;
190191 }
191192
192- /**
193- * Converts a promise rejection reason to a string message.
194- *
195- * String(obj) gives "[object Object]" and JSON.stringify("str")
196- * adds unwanted quotes.
197- *
198- * @param reason - The rejection reason from PromiseRejectionEvent
199- */
200- private stringifyReason ( reason : unknown ) : string {
201- if ( reason instanceof Error ) {
202- return reason . message ;
203- }
204- if ( typeof reason === 'string' ) {
205- return reason ;
206- }
207-
208- return JSON . stringify ( Sanitizer . sanitize ( reason ) ) ;
209- }
210-
211193 /**
212194 * Creates a console log event from an error or promise rejection
213195 *
@@ -231,7 +213,7 @@ export class ConsoleCatcher {
231213 method : 'error' ,
232214 timestamp : new Date ( ) ,
233215 type : 'UnhandledRejection' ,
234- message : this . stringifyReason ( event . reason ) ,
216+ message : stringifyRejectionReason ( event . reason ) ,
235217 stack : event . reason ?. stack || '' ,
236218 fileLine : '' ,
237219 } ;
Original file line number Diff line number Diff line change @@ -80,3 +80,22 @@ export function getErrorFromEvent(event: ErrorEvent | PromiseRejectionEvent): Er
8080
8181 return Sanitizer . sanitize ( error ) ;
8282}
83+
84+ /**
85+ * Converts a promise rejection reason to a string message.
86+ *
87+ * String(obj) gives "[object Object]" and JSON.stringify("str")
88+ * adds unwanted quotes.
89+ *
90+ * @param reason - The rejection reason from PromiseRejectionEvent
91+ */
92+ export function stringifyRejectionReason ( reason : unknown ) : string {
93+ if ( reason instanceof Error ) {
94+ return reason . message ;
95+ }
96+ if ( typeof reason === 'string' ) {
97+ return reason ;
98+ }
99+
100+ return JSON . stringify ( Sanitizer . sanitize ( reason ) ) ;
101+ }
You can’t perform that action at this time.
0 commit comments