@@ -39,7 +39,11 @@ describe('BacktraceInterceptor', () => {
3939
4040 class Filter extends BaseExceptionFilter {
4141 catch ( exception : unknown , host : ArgumentsHost ) : void {
42- handler . handleException ( exception , host ) ;
42+ try {
43+ handler . handleException ( exception , host ) ;
44+ } catch ( err ) {
45+ // Do nothing
46+ }
4347 super . catch ( exception , host ) ;
4448 }
4549 }
@@ -122,6 +126,57 @@ describe('BacktraceInterceptor', () => {
122126 expect ( send ) . not . toBeCalled ( ) ;
123127 } ) ;
124128
129+ it ( 'should throw if client is uninitialized' , async ( ) => {
130+ const error = new Error ( 'foo' ) ;
131+
132+ @Controller ( )
133+ class TestController {
134+ @Get ( 'error' )
135+ public error ( ) {
136+ throw error ;
137+ }
138+ }
139+
140+ const interceptor = new BacktraceExceptionHandler ( { } ) ;
141+ const handleException = jest . spyOn ( interceptor , 'handleException' ) ;
142+
143+ const { app } = await createAppWithHandler ( interceptor , TestController ) ;
144+
145+ await app . init ( ) ;
146+ await request ( app . getHttpServer ( ) ) . get ( '/error' ) . expect ( 500 ) ;
147+
148+ const result = handleException . mock . results [ 0 ] ;
149+ expect ( result . type ) . toEqual ( 'throw' ) ;
150+ expect ( result . value ) . toBeInstanceOf ( Error ) ;
151+ expect ( result . value . message ) . toBe ( 'Backtrace instance is unavailable. Initialize the client first.' ) ;
152+ } ) ;
153+
154+ it ( 'should not throw if client is uninitialized and skipIfClientUndefined is true' , async ( ) => {
155+ const error = new Error ( 'foo' ) ;
156+
157+ @Controller ( )
158+ class TestController {
159+ @Get ( 'error' )
160+ public error ( ) {
161+ throw error ;
162+ }
163+ }
164+
165+ const interceptor = new BacktraceExceptionHandler ( {
166+ skipIfClientUndefined : true ,
167+ } ) ;
168+ const handleException = jest . spyOn ( interceptor , 'handleException' ) ;
169+
170+ const { app } = await createAppWithHandler ( interceptor , TestController ) ;
171+
172+ await app . init ( ) ;
173+ await request ( app . getHttpServer ( ) ) . get ( '/error' ) . expect ( 500 ) ;
174+
175+ const result = handleException . mock . results [ 0 ] ;
176+ expect ( result . type ) . not . toEqual ( 'throw' ) ;
177+ expect ( result . value ) . toBe ( false ) ;
178+ } ) ;
179+
125180 describe ( 'include' , ( ) => {
126181 it ( 'should not send when error type is not on include list' , async ( ) => {
127182 const error = new BadRequestException ( 'abc' ) ;
0 commit comments