Skip to content

Commit a8ca909

Browse files
committed
fix(remix): Do not capture thrown redirect responses.
1 parent 35906d0 commit a8ca909

File tree

6 files changed

+36
-5
lines changed

6 files changed

+36
-5
lines changed

packages/remix/src/utils/instrumentServer.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ export function wrapRemixHandleError(err: unknown, { request }: DataFunctionArgs
106106
export async function captureRemixServerException(err: unknown, name: string, request: Request): Promise<void> {
107107
// Skip capturing if the thrown error is not a 5xx response
108108
// https://remix.run/docs/en/v1/api/conventions#throwing-responses-in-loaders
109-
if (IS_REMIX_V2) {
110-
if (isRouteErrorResponse(err) && err.status < 500) {
111-
return;
112-
}
113-
} else if (isResponse(err) && err.status < 500) {
109+
if (isResponse(err) && err.status < 500) {
114110
return;
115111
}
116112

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from '../../common/routes/throw-redirect';
2+
export { default } from '../../common/routes/throw-redirect';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from '../../common/routes/throw-redirect';
2+
export { default } from '../../common/routes/throw-redirect';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { LoaderFunction, redirect } from '@remix-run/node';
2+
import { useLoaderData } from '@remix-run/react';
3+
4+
export const loader: LoaderFunction = async () => {
5+
throw redirect('/');
6+
};
7+
8+
export default function ThrowRedirect() {
9+
const data = useLoaderData();
10+
return <div>{data}</div>;
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { expect, test } from '@playwright/test';
2+
import { countEnvelopes } from './utils/helpers';
3+
4+
test('should not report thrown redirect response on client side.', async ({ page }) => {
5+
const count = await countEnvelopes(page, { url: '/throw-redirect', envelopeType: 'event' });
6+
7+
expect(count).toBe(0);
8+
});

packages/remix/test/integration/test/server/loader.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,16 @@ describe.each(['builtin', 'express'])('Remix API Loaders with adapter = %s', ada
241241
],
242242
});
243243
});
244+
245+
it('does not capture thrown redirect responses', async () => {
246+
const env = await RemixTestEnv.init(adapter);
247+
const url = `${env.url}/throw-redirect`;
248+
249+
const envelopesCount = await env.countEnvelopes({
250+
url,
251+
envelopeType: ['event'],
252+
});
253+
254+
expect(envelopesCount).toBe(0);
255+
});
244256
});

0 commit comments

Comments
 (0)