Skip to content

Remix: Throwing a 4XX/5XX Response causes a "body already used for" error #5423

Closed
@dmarkow

Description

@dmarkow

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/remix

SDK Version

7.7.0

Framework Version

7.7.0

Link to Sentry event

No response

Steps to Reproduce

Remix lets you throw responses for things like a 404 Not Found:

export const loader = async () => {
  throw new Response("Not Found", { status: 404 });
};

You would then use a remix CatchBoundary to catch the 404 and display a message. To reproduce, just add the loader above to any route and try to open the page.

Expected Result

Sentry should pass the 404 through and allow the CatchBoundary to show it. It worked fine in 7.6.0.

Actual Result

As of 7.7.0, @sentry/remix is causing the following error when loading any page that throws a response. It only happens if the page was server rendered, e.g. given a route /foo that throws a 404, if I load /foo directly and it server renders, it crashes with the error below. If I load / first, then navigate client-side to /foo, it uses the catch boundary properly. I assume this is related to the updates in #5405 since it worked fine in 7.6.0 and that PR addressed some thrown responses.

TypeError: body used already for: 
    at consumeBody (/Users/dylan/dev/smp/node_modules/@remix-run/web-fetch/src/body.js:205:9)
    at NodeResponse.text (/Users/dylan/dev/smp/node_modules/@remix-run/web-fetch/src/body.js:171:24)
    at Object.extractData (/Users/dylan/dev/smp/node_modules/@remix-run/server-runtime/dist/data.js:138:19)
    at handleDocumentRequest (/Users/dylan/dev/smp/node_modules/@remix-run/server-runtime/dist/server.js:331:28)
    at requestHandler (/Users/dylan/dev/smp/node_modules/@remix-run/server-runtime/dist/server.js:49:18)
    at /Users/dylan/dev/smp/node_modules/@sentry/remix/cjs/utils/instrumentServer.js:167:16
    at /Users/dylan/dev/smp/node_modules/@remix-run/express/dist/server.js:39:22

It's just raw text from the server, not handled by any ErrorBoundary. If I throw a standard Error object instead, it uses the ErrorBoundary.

Metadata

Metadata

Assignees

Labels

Package: remixIssues related to the Sentry Remix SDK

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions