File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed
libraries/nestjs-libraries/src/integrations Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,20 @@ export class NotEnoughScopes {
3030 constructor ( public message = 'Not enough scopes' ) { }
3131}
3232
33+ function safeStringify ( obj : any ) {
34+ const seen = new WeakSet ( ) ;
35+
36+ return JSON . stringify ( obj , ( key , value ) => {
37+ if ( typeof value === 'object' && value !== null ) {
38+ if ( seen . has ( value ) ) {
39+ return '[Circular]' ;
40+ }
41+ seen . add ( value ) ;
42+ }
43+ return value ;
44+ } ) ;
45+ }
46+
3347export abstract class SocialAbstract {
3448 abstract identifier : string ;
3549 maxConcurrentJob = 1 ;
@@ -62,20 +76,20 @@ export abstract class SocialAbstract {
6276 try {
6377 value = await func ( ) ;
6478 } catch ( err ) {
65- const handle = this . handleErrors ( JSON . stringify ( err ) ) ;
79+ const handle = this . handleErrors ( safeStringify ( err ) ) ;
6680 value = { err : true , value : 'Unknown Error' , ...( handle || { } ) } ;
6781 }
6882
6983 if ( value && value ?. err && value ?. value ) {
7084 if ( value . type === 'refresh-token' ) {
7185 throw new RefreshToken (
7286 '' ,
73- JSON . stringify ( { } ) ,
87+ safeStringify ( { } ) ,
7488 { } as any ,
7589 value . value || ''
7690 ) ;
7791 }
78- throw new BadBody ( '' , JSON . stringify ( { } ) , { } as any , value . value || '' ) ;
92+ throw new BadBody ( '' , safeStringify ( { } ) , { } as any , value . value || '' ) ;
7993 }
8094
8195 return value ;
You can’t perform that action at this time.
0 commit comments