An interceptor implements NestInterceptor and wraps handler execution using RxJS Observable. It runs both before and after the controller handler. Its unique capabilities include transforming the response, measuring execution time, caching (short-circuiting before the handler), overriding exceptions, and adding pre/post logic around the full handler call.
Transform the response — wrap in an envelope, rename fields, strip sensitive data.
Short-circuit the handler — return a cached observable before calling next.handle().
Measure execution time — spans from before next.handle() to after the stream completes.
Remap exceptions — use catchError() to convert domain errors into HTTP errors.
Add retry logic — use retryWhen() to automatically retry failed handler calls.
Override the return value — next.handle() returns an Observable you control fully.