Next.js Discord

Discord Forum

Common error handling for api routes

Unanswered
Giant wood wasp posted this in #help-forum
Open in Discord
Giant wood waspOP
Whenever an error occurs in an api route, I want three things to happen. Newrelic should register this, sentry should register an error, we log the error with pino. I believe the frameworks from newrelic & sentry handles this automatically if I let them. However I don't know how to tell nextjs to log with pino, and in what format. So I've written a wrapper like withApiErrorHandling(myNextApiHandler) that does this. Is this the recommended way, or is there some config like onError I could use for pino logging? Middlewares doesn't seem to be the right tool?

0 Replies