Overview - Why interceptors add cross-cutting logic
What is it?
Interceptors in NestJS are special pieces of code that run before or after a function handles a request. They let you add extra behavior that applies to many parts of your app without changing each part individually. This extra behavior is called cross-cutting logic because it crosses over many different functions or modules.
Why it matters
Without interceptors, you would have to repeat the same code in many places, like logging or error handling, which makes your app harder to maintain and more error-prone. Interceptors let you keep your code clean and organized by separating these common tasks from your main business logic.
Where it fits
Before learning about interceptors, you should understand basic NestJS controllers and middleware. After mastering interceptors, you can explore advanced topics like custom decorators and exception filters to further organize your app's behavior.