Friday 22 February 2019

How do I prevent node from logging an exception to the console in my NextJS/Express app?

I have an Express application that runs a blog in a NextJS app, very similar to the example in their repo

I have set it up so that my app runs a query to fetch a blog article, and if the result is empty it throws a NotFoundException.

I catch this exception in my NextJS _error.js file, which is similar to a React error boundary, where I route the user to my 404 page. This part works fine.

The problem I'm having is that this exception is logged to the node console even though I'm not logging it when catching the exception. This pollutes our company's logging software with all our 404's

Is there some node/express setting I'm missing here that prevents the logging of exceptions? Here's my Express process error handler:

process.on('unhandledRejection', (reason, promise) =>
    console.error(`Unhandled Rejection at: ${promise}.\nreason: ${reason.stack || reason}`));

I know there is a log there, but the format of the one I want to eliminate is different to this, so I'm confident this is not the source.



from How do I prevent node from logging an exception to the console in my NextJS/Express app?

No comments:

Post a Comment