@@ -25,7 +25,7 @@ const SENSITIVE_FIELDS = [
2525] ;
2626
2727const SENSITIVE_FIELD_PATTERNS = SENSITIVE_FIELDS . map (
28- ( field ) => new RegExp ( `"${ field } "\\ s*:\ \s*"[^"]*"` , 'gi' ) ,
28+ ( field ) => new RegExp ( String . raw `"${ field } "\s*:\s*"[^"]*"` , 'gi' ) ,
2929) ;
3030
3131const isSensitiveField = ( key : string ) : boolean => {
@@ -114,7 +114,7 @@ export const cleanLogEvent = (logEvent: any) => {
114114
115115 if ( isSensitiveField ( key ) ) {
116116 eventData [ key ] = REDACTED ;
117- } else if ( key === 'res' && value && value . raw ) {
117+ } else if ( key === 'res' && value ? .raw ) {
118118 extractRequestFields ( value , eventData , logEvent ) ;
119119 } else if ( value instanceof Error ) {
120120 extractErrorFields ( key , value , eventData , logEvent ) ;
@@ -173,11 +173,15 @@ function extractErrorFields(
173173 eventData [ errorKey + 'Params' ] = stringify (
174174 redactSensitiveFields ( value . error . params ) ,
175175 ) ;
176- } else if ( Object . keys ( context ) . length ) {
176+ } else if ( context && Object . keys ( context ) . length ) {
177177 eventData [ errorKey + 'Context' ] = stringify ( redactSensitiveFields ( context ) ) ;
178178 }
179179}
180180
181181function stringify ( value : any ) {
182- return truncate ( JSON . stringify ( value ) ) ;
182+ try {
183+ return truncate ( JSON . stringify ( value ) ) ;
184+ } catch ( error ) {
185+ return `Logger error - could not stringify object. ${ error } ` ;
186+ }
183187}
0 commit comments