@@ -17,10 +17,16 @@ test.beforeEach((ctx) => {
1717 function handler ( arg1 , arg2 , arg3 ) {
1818 return `${ arg1 } , ${ arg2 } , ${ arg3 } `
1919 }
20+ const txInfo = { }
21+ wrapper . extractTxInfo = function ( ) {
22+ const request = { }
23+ return { txInfo, request, errorWare : false }
24+ }
2025 ctx . nr = {
2126 agent,
2227 handler,
2328 logger,
29+ txInfo,
2430 wrapper
2531 }
2632} )
@@ -69,3 +75,44 @@ test('should run wrapped handler in context if transaction present, and properly
6975 end ( )
7076 } )
7177} )
78+
79+ test ( 'should handle error when passed in to done handler' , function ( t , end ) {
80+ const { agent, txInfo, wrapper } = t . nr
81+ const error = new Error ( 'test error' )
82+ function handler ( req , res , next ) {
83+ next ( error )
84+ }
85+ const route = '/test/url'
86+ const wrapped = wrapper . wrap ( { handler, route } )
87+ helper . runInTransaction ( agent , function ( tx ) {
88+ tx . type = 'web'
89+ tx . url = route
90+ wrapped ( 'one' , 'two' , function ( ) { } )
91+ assert . deepEqual ( txInfo . error , error )
92+ assert . equal ( txInfo . errorHandled , false )
93+
94+ tx . end ( )
95+ end ( )
96+ } )
97+ } )
98+
99+ test ( 'should nothandle error when isError is not using default handler' , function ( t , end ) {
100+ const { agent, txInfo, wrapper } = t . nr
101+ const error = new Error ( 'test error' )
102+ function handler ( req , res , next ) {
103+ next ( error )
104+ }
105+ const route = '/test/url'
106+ const wrapped = wrapper . wrap ( { handler, route } )
107+ wrapper . isError = function ( _err ) {
108+ return false
109+ }
110+ helper . runInTransaction ( agent , function ( tx ) {
111+ tx . type = 'web'
112+ tx . url = route
113+ wrapped ( 'one' , 'two' , function ( ) { } )
114+ assert . deepEqual ( txInfo , { } )
115+ tx . end ( )
116+ end ( )
117+ } )
118+ } )
0 commit comments