Menu

1 / 5

NestJS error handling in production: exception filters, error tracking and alerts

DEV Community: nestjs·Kamil Mysliwiec·4 days ago
#Bgc04USE
#devtonestjs#devto#dev#error#errors
Reading 0:00
15s threshold

Nest gives you a solid answer to "what should the client see when something goes wrong". That's what exception filters are for. What it intentionally doesn't cover is the other half: what should you see, and when?

I want to go through both here. How errors move through a Nest app, the one distinction that makes error data useful instead of noisy, and how to get from "an exception was thrown" to "we know about it, we know it's new, and we know which line".

How an error travels through Nest

Anything thrown in a guard, pipe, interceptor, controller or provider bubbles up to the exceptions layer, where the built-in ExceptionsHandler (a BaseExceptionFilter ) deals with it. If it's an HttpException (or a subclass like NotFoundException or BadRequestException ), the client gets that status and response body. If it's anything else, say a TypeError , a driver error or a rejected promise, the client gets a plain 500 Internal Server Error and the details stay on the server.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.