Skip to content

Commit a9c43ad

Browse files
onurtemizkanAbhiPrasadlizokm
authored
Add wrapRemixHandleError instructions (#8681)
Co-authored-by: Abhijeet Prasad <[email protected]> Co-authored-by: Liza Mock <[email protected]>
1 parent d712075 commit a9c43ad

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/platforms/javascript/guides/remix/manual-setup.mdx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,23 @@ export const ErrorBoundary: V2_ErrorBoundaryComponent = () => {
167167

168168
## v2 Server-side Errors
169169

170-
Sentry won't be able to capture your server-side errors automatically if you're using the`v2_errorBoundary` future flag. To work around this, define a [`handleError`](https://remix.run/docs/en/main/file-conventions/entry.server#handleerror) function in your server entry point. Then use `Sentry.captureRemixServerException` to capture errors in your server-side code.
170+
Sentry won't be able to capture your unexpected server-side errors automatically on Remix v2. To work around this, instrument the [`handleError`](https://remix.run/docs/en/main/file-conventions/entry.server#handleerror) function in your server entry point.
171171

172-
```typescript {filename: entry.server.tsx}
172+
If you're using Sentry Remix SDK version `7.87.0` or higher, you can use `wrapRemixHandleError` to export as your `handleError` function.
173+
174+
```typescript {filename: entry.server.tsx (@sentry/remix >= 7.87.0)}
175+
import { wrapRemixHandleError } from "@sentry/remix";
176+
177+
export const handleError = wrapRemixHandleError;
178+
```
179+
180+
For SDK versions older than `7.87.0`, you can use `Sentry.captureRemixServerException` to capture errors inside `handleError`.
181+
182+
```typescript {filename: entry.server.tsx (@sentry/remix < 7.87.0)}
173183
export function handleError(
174184
error: unknown,
175185
{ request }: DataFunctionArgs
176186
): void {
177-
if (error instanceof Error) {
178187
Sentry.captureRemixServerException(error, "remix.server", request);
179188
} else {
180189
// Optionally capture non-Error objects
@@ -187,7 +196,7 @@ After you've completed this setup, the SDK will automatically capture unhandled
187196

188197
<Note>
189198

190-
You can refer to [Remix Docs](https://remix.run/docs/en/v1/guides/envvars#browser-environment-variables) to learn how to use your Sentry DSN with environment variables.
199+
You can refer to [Remix Docs](https://remix.run/docs/en/main/guides/envvars#browser-environment-variables) to learn how to use your Sentry DSN with environment variables.
191200

192201
</Note>
193202

@@ -197,7 +206,7 @@ To enable readable stack traces, <PlatformLink to="/sourcemaps">configure source
197206

198207
## Custom Express Server
199208

200-
If you use a custom Express server in your Remix application, you should wrap your [`createRequestHandler` function](https://remix.run/docs/en/v1/other-api/adapter#createrequesthandler) manually with `wrapExpressCreateRequestHandler`. This isn't necessary if you're using the built-in Remix App Server.
209+
If you use a custom Express server in your Remix application, you should wrap your [`createRequestHandler` function](https://remix.run/docs/en/main/other-api/adapter#createrequesthandler) manually with `wrapExpressCreateRequestHandler`. This isn't necessary if you're using the built-in Remix App Server.
201210

202211
<Note>
203212

@@ -217,7 +226,7 @@ const createSentryRequestHandler =
217226
app.all("*", createSentryRequestHandler(/* ... */));
218227
```
219228

220-
The function returned by `wrapExpressCreateRequestHandler` accepts the build object as its first parameter. So if your boilerplate code passes the argument as a function, you need to update the usage. For example, if you're using Vite, you need to await the build loader before passing it to the wrapped handler.
229+
The function returned by `wrapExpressCreateRequestHandler` accepts the build object as its first parameter. So if your boilerplate code passes the argument as a function, you need to update the usage. For example, if you're using [Vite](https://remix.run/docs/en/main/future/vite), you'll need to wait for the build loader before passing it to the wrapped handler.
221230

222231
```diff {filename: server/index.ts}
223232
wrapExpressCreateRequestHandler(createRequestHandler)({

0 commit comments

Comments
 (0)