CodePark/ questions / Interceptors
START PRACTICINGPRACTICE
Backend question · NestJS › Interceptors

Interceptors are bound globally (G), on the controller (C) and on the route (R). In what order does their code run before and after the handler?

Before: G, C, R. After: R, C, G

On the way in, interceptors run from global to controller to route. On the way out, the observables unwind like nested function calls. So the after-logic runs in reverse: route, then controller, then global.

"Before: G, C, R. After: G, C, R" is wrong. Running the same order both ways would mean the outermost wrapper finishes first. Nested streams don't work that way: the innermost one finishes first.