Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v8][node][express] setupExpressErrorHandler doesn't catch the errors #12113

Closed
3 tasks done
xr0master opened this issue May 18, 2024 · 2 comments · Fixed by getsentry/sentry-docs#10092
Closed
3 tasks done

Comments

@xr0master
Copy link
Contributor

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.2.1

Framework Version

express.js

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

If there is a similar router as below, then setupExpressErrorHandler does not work.

app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
  return error ? res.status(400).send(error.message).end() : next();
});

Sentry.setupExpressErrorHandler(app);

We can swap them as a workaround. In this case, the Sentry will catch errors, and the response will be returned as expected.

Sentry.setupExpressErrorHandler(app);

app.use((error: Error, req: Request, res: Response, next: NextFunction) => {
  return error ? res.status(400).send(error.message).end() : next();
});

Expected Result

work

Actual Result

doesn't work

@amiranvarov
Copy link

image

this part made gave me good laugh 🤣

@mydea
Copy link
Member

mydea commented May 21, 2024

Hey,

yeah, sorry about that, we have not documented this ideally. You have to call setupExpressErrorHandler() after your routes are defined, but before all other middlewares. I'll fix this in the docs too!

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

Successfully merging a pull request may close this issue.

4 participants