Skip to content

Improve Sentry.captureRemixServerException #9695

Description

@AbhiPrasad

Turn snippet in https://docs.sentry.io/platforms/javascript/guides/remix/manual-setup/#v2-server-side-errors to handle non-error objects

export function handleError(
  error: unknown,
  { request }: DataFunctionArgs
): void {
  if (error instanceof Error) {
    Sentry.captureRemixServerException(error, "remix.server", request);
  } else {
    // Optionally capture non-Error objects
    Sentry.captureException(error);
  }
}
export function handleError(
  error: unknown,
  { request }: DataFunctionArgs
): void {
  Sentry.captureRemixServerException(error, "remix.server", request);
}

Ideally we can even do a wrapper for handleError

export const handleError = Sentry.wrapRemixHandleError;

We also need to check for error.error to identify an error:

{
  "data": "Error: No route matches URL \"/wp-login.php\"",
  "error": {
    "message": "No route matches URL \"/wp-login.php\"",
    "name": "Error",
    "stack": "Error: No route matches URL \"/wp-login.php\"\n    at getInternalRouterError (/app/apps/web/build/server.js:38878:63)\n    at Object.query (/app/apps/web/build/server.js:37976:23)\n    at handleDocumentRequestRR (/app/apps/web/build/server.js:40006:39)\n    at requestHandler (/app/apps/web/build/server.js:39939:28)\n    at /app/apps/web/build/server.js:41126:32"
  },
  "internal": true,
  "status": 404,
  "statusText": "Not Found"
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions