@@ -185,4 +185,204 @@ describe.each(['builtin', 'express'])('Remix API Actions with adapter = %s', ada
185185 } ,
186186 } ) ;
187187 } ) ;
188+
189+ it ( 'handles a thrown `json()` error response with `statusText`' , async ( ) => {
190+ const env = await RemixTestEnv . init ( adapter ) ;
191+ const url = `${ env . url } /action-json-response/-3` ;
192+
193+ const envelopes = await env . getMultipleEnvelopeRequest ( {
194+ url,
195+ count : 2 ,
196+ method : 'post' ,
197+ envelopeType : [ 'transaction' , 'event' ] ,
198+ } ) ;
199+
200+ const [ transaction ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'transaction' ) ;
201+ const [ event ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'event' ) ;
202+
203+ assertSentryTransaction ( transaction [ 2 ] , {
204+ contexts : {
205+ trace : {
206+ op : 'http.server' ,
207+ status : 'internal_error' ,
208+ tags : {
209+ method : 'POST' ,
210+ 'http.status_code' : '500' ,
211+ } ,
212+ } ,
213+ } ,
214+ tags : {
215+ transaction : 'routes/action-json-response/$id' ,
216+ } ,
217+ } ) ;
218+
219+ assertSentryEvent ( event [ 2 ] , {
220+ exception : {
221+ values : [
222+ {
223+ type : 'Error' ,
224+ value : 'Sentry Test Error' ,
225+ stacktrace : expect . any ( Object ) ,
226+ mechanism : {
227+ data : {
228+ function : 'action' ,
229+ } ,
230+ handled : true ,
231+ type : 'instrument' ,
232+ } ,
233+ } ,
234+ ] ,
235+ } ,
236+ } ) ;
237+ } ) ;
238+
239+ it ( 'handles a thrown `json()` error response without `statusText`' , async ( ) => {
240+ const env = await RemixTestEnv . init ( adapter ) ;
241+ const url = `${ env . url } /action-json-response/-4` ;
242+
243+ const envelopes = await env . getMultipleEnvelopeRequest ( {
244+ url,
245+ count : 2 ,
246+ method : 'post' ,
247+ envelopeType : [ 'transaction' , 'event' ] ,
248+ } ) ;
249+
250+ const [ transaction ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'transaction' ) ;
251+ const [ event ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'event' ) ;
252+
253+ assertSentryTransaction ( transaction [ 2 ] , {
254+ contexts : {
255+ trace : {
256+ op : 'http.server' ,
257+ status : 'internal_error' ,
258+ tags : {
259+ method : 'POST' ,
260+ 'http.status_code' : '500' ,
261+ } ,
262+ } ,
263+ } ,
264+ tags : {
265+ transaction : 'routes/action-json-response/$id' ,
266+ } ,
267+ } ) ;
268+
269+ assertSentryEvent ( event [ 2 ] , {
270+ exception : {
271+ values : [
272+ {
273+ type : 'Error' ,
274+ value : 'Non-Error exception captured with keys: data' ,
275+ stacktrace : expect . any ( Object ) ,
276+ mechanism : {
277+ data : {
278+ function : 'action' ,
279+ } ,
280+ handled : true ,
281+ type : 'instrument' ,
282+ } ,
283+ } ,
284+ ] ,
285+ } ,
286+ } ) ;
287+ } ) ;
288+
289+ it ( 'handles a thrown `json()` error response with string body' , async ( ) => {
290+ const env = await RemixTestEnv . init ( adapter ) ;
291+ const url = `${ env . url } /action-json-response/-5` ;
292+
293+ const envelopes = await env . getMultipleEnvelopeRequest ( {
294+ url,
295+ count : 2 ,
296+ method : 'post' ,
297+ envelopeType : [ 'transaction' , 'event' ] ,
298+ } ) ;
299+
300+ const [ transaction ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'transaction' ) ;
301+ const [ event ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'event' ) ;
302+
303+ assertSentryTransaction ( transaction [ 2 ] , {
304+ contexts : {
305+ trace : {
306+ op : 'http.server' ,
307+ status : 'internal_error' ,
308+ tags : {
309+ method : 'POST' ,
310+ 'http.status_code' : '500' ,
311+ } ,
312+ } ,
313+ } ,
314+ tags : {
315+ transaction : 'routes/action-json-response/$id' ,
316+ } ,
317+ } ) ;
318+
319+ assertSentryEvent ( event [ 2 ] , {
320+ exception : {
321+ values : [
322+ {
323+ type : 'Error' ,
324+ value : 'Sentry Test Error [string body]' ,
325+ stacktrace : expect . any ( Object ) ,
326+ mechanism : {
327+ data : {
328+ function : 'action' ,
329+ } ,
330+ handled : true ,
331+ type : 'instrument' ,
332+ } ,
333+ } ,
334+ ] ,
335+ } ,
336+ } ) ;
337+ } ) ;
338+
339+ it ( 'handles a thrown `json()` error response with an empty object' , async ( ) => {
340+ const env = await RemixTestEnv . init ( adapter ) ;
341+ const url = `${ env . url } /action-json-response/-6` ;
342+
343+ const envelopes = await env . getMultipleEnvelopeRequest ( {
344+ url,
345+ count : 2 ,
346+ method : 'post' ,
347+ envelopeType : [ 'transaction' , 'event' ] ,
348+ } ) ;
349+
350+ const [ transaction ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'transaction' ) ;
351+ const [ event ] = envelopes . filter ( envelope => envelope [ 1 ] . type === 'event' ) ;
352+
353+ assertSentryTransaction ( transaction [ 2 ] , {
354+ contexts : {
355+ trace : {
356+ op : 'http.server' ,
357+ status : 'internal_error' ,
358+ tags : {
359+ method : 'POST' ,
360+ 'http.status_code' : '500' ,
361+ } ,
362+ } ,
363+ } ,
364+ tags : {
365+ transaction : 'routes/action-json-response/$id' ,
366+ } ,
367+ } ) ;
368+
369+ assertSentryEvent ( event [ 2 ] , {
370+ exception : {
371+ values : [
372+ {
373+ type : 'Error' ,
374+ value : 'Non-Error exception captured with keys: [object has no keys]' ,
375+ stacktrace : expect . any ( Object ) ,
376+ mechanism : {
377+ data : {
378+ function : 'action' ,
379+ } ,
380+ handled : true ,
381+ type : 'instrument' ,
382+ } ,
383+ } ,
384+ ] ,
385+ } ,
386+ } ) ;
387+ } ) ;
188388} ) ;
0 commit comments