@@ -53,3 +53,97 @@ test('sends error with parameterized transaction name', async ({ baseURL }) => {
5353
5454 expect ( errorEvent ?. transaction ) . toBe ( 'GET /test-error/{id}' ) ;
5555} ) ;
56+
57+ test ( 'Does not send errors to Sentry if boom throws in "onPreResponse" after JS error in route handler' , async ( {
58+ baseURL,
59+ } ) => {
60+ let errorEventOccurred = false ;
61+
62+ waitForError ( 'node-hapi' , event => {
63+ if ( event . exception ?. values ?. [ 0 ] ?. value ?. includes ( 'This is a JS error (boom in onPreResponse)' ) ) {
64+ errorEventOccurred = true ;
65+ }
66+ return false ; // expects to return a boolean (but not relevant here)
67+ } ) ;
68+
69+ const transactionEventPromise4xx = waitForTransaction ( 'node-hapi' , transactionEvent => {
70+ return transactionEvent ?. transaction === 'GET /test-failure-boom-4xx' ;
71+ } ) ;
72+
73+ const transactionEventPromise5xx = waitForTransaction ( 'node-hapi' , transactionEvent => {
74+ return transactionEvent ?. transaction === 'GET /test-failure-boom-5xx' ;
75+ } ) ;
76+
77+ const response4xx = await fetch ( `${ baseURL } /test-failure-boom-4xx` ) ;
78+ const response5xx = await fetch ( `${ baseURL } /test-failure-boom-5xx` ) ;
79+
80+ expect ( response4xx . status ) . toBe ( 404 ) ;
81+ expect ( response5xx . status ) . toBe ( 504 ) ;
82+
83+ const transactionEvent4xx = await transactionEventPromise4xx ;
84+ const transactionEvent5xx = await transactionEventPromise5xx ;
85+
86+ expect ( errorEventOccurred ) . toBe ( false ) ;
87+ expect ( transactionEvent4xx . transaction ) . toBe ( 'GET /test-failure-boom-4xx' ) ;
88+ expect ( transactionEvent5xx . transaction ) . toBe ( 'GET /test-failure-boom-5xx' ) ;
89+ } ) ;
90+
91+ test ( 'Does not send error to Sentry if error response is overwritten with 2xx in "onPreResponse"' , async ( {
92+ baseURL,
93+ } ) => {
94+ let errorEventOccurred = false ;
95+
96+ waitForError ( 'node-hapi' , event => {
97+ if ( event . exception ?. values ?. [ 0 ] ?. value ?. includes ( 'This is a JS error (2xx override in onPreResponse)' ) ) {
98+ errorEventOccurred = true ;
99+ }
100+ return false ; // expects to return a boolean (but not relevant here)
101+ } ) ;
102+
103+ const transactionEventPromise = waitForTransaction ( 'node-hapi' , transactionEvent => {
104+ return transactionEvent ?. transaction === 'GET /test-failure-2xx-override-onPreResponse' ;
105+ } ) ;
106+
107+ const response = await fetch ( `${ baseURL } /test-failure-2xx-override-onPreResponse` ) ;
108+
109+ const transactionEvent = await transactionEventPromise ;
110+
111+ expect ( response . status ) . toBe ( 200 ) ;
112+ expect ( errorEventOccurred ) . toBe ( false ) ;
113+ expect ( transactionEvent . transaction ) . toBe ( 'GET /test-failure-2xx-override-onPreResponse' ) ;
114+ } ) ;
115+
116+ test ( 'Only sends onPreResponse error to Sentry if JS error is thrown in route handler AND onPreResponse' , async ( {
117+ baseURL,
118+ } ) => {
119+ const errorEventPromise = waitForError ( 'node-hapi' , errorEvent => {
120+ return errorEvent ?. exception ?. values ?. [ 0 ] ?. value ?. includes ( 'JS error (onPreResponse)' ) || false ;
121+ } ) ;
122+
123+ let routeHandlerErrorOccurred = false ;
124+
125+ waitForError ( 'node-hapi' , event => {
126+ if (
127+ ! event . type &&
128+ event . exception ?. values ?. [ 0 ] ?. value ?. includes ( 'This is an error (another JS error in onPreResponse)' )
129+ ) {
130+ routeHandlerErrorOccurred = true ;
131+ }
132+ return false ; // expects to return a boolean (but not relevant here)
133+ } ) ;
134+
135+ const transactionEventPromise = waitForTransaction ( 'node-hapi' , transactionEvent => {
136+ return transactionEvent ?. transaction === 'GET /test-failure-JS-error-onPreResponse' ;
137+ } ) ;
138+
139+ const response = await fetch ( `${ baseURL } /test-failure-JS-error-onPreResponse` ) ;
140+
141+ expect ( response . status ) . toBe ( 500 ) ;
142+
143+ const errorEvent = await errorEventPromise ;
144+ const transactionEvent = await transactionEventPromise ;
145+
146+ expect ( routeHandlerErrorOccurred ) . toBe ( false ) ;
147+ expect ( transactionEvent . transaction ) . toBe ( 'GET /test-failure-JS-error-onPreResponse' ) ;
148+ expect ( errorEvent . transaction ) . toEqual ( 'GET /test-failure-JS-error-onPreResponse' ) ;
149+ } ) ;
0 commit comments