1+ function filterError ( input ) {
2+ return {
3+ errorType : input . name ,
4+ message : input . message ,
5+ stack : input . stack ,
6+ ...( input . code ? { code : input . code } : { } ) ,
7+ ...( input . statusCode ? { statusCode : input . statusCode } : { } ) ,
8+ }
9+ }
10+
111const deepMap = ( input , handler = v => v , path = [ '$' ] , seen = new Set ( [ input ] ) ) => {
12+ // this is in an effort to maintain bole's error logging behavior
13+ if ( path . join ( '.' ) === '$' && input instanceof Error ) {
14+ return deepMap ( { err : filterError ( input ) } , handler , path , seen )
15+ }
16+ if ( input instanceof Error ) {
17+ return deepMap ( filterError ( input ) , handler , path , seen )
18+ }
19+ if ( input instanceof Buffer ) {
20+ return `[unable to log instanceof buffer]`
21+ }
22+ if ( input instanceof Uint8Array ) {
23+ return `[unable to log instanceof Uint8Array]`
24+ }
25+
226 if ( Array . isArray ( input ) ) {
327 const result = [ ]
428 for ( let i = 0 ; i < input . length ; i ++ ) {
@@ -21,11 +45,6 @@ const deepMap = (input, handler = v => v, path = ['$'], seen = new Set([input]))
2145 } else if ( typeof input === 'object' || typeof input === 'function' ) {
2246 const result = { }
2347
24- if ( input instanceof Error ) {
25- // `name` property is not included in `Object.getOwnPropertyNames(error)`
26- result . errorType = input . name
27- }
28-
2948 for ( const propertyName of Object . getOwnPropertyNames ( input ) ) {
3049 // skip logging internal properties
3150 if ( propertyName . startsWith ( '_' ) ) {
0 commit comments