How do global, controller and route handlers interact?
Try code in the playgroundUnderstand the concept
Nest can attach request handlers at global, controller and route scopes. Scope determines which requests a handler applies to, while handler type determines execution order. Interceptors wrap inner work and unwind on the response path; exception filters select a matching handler rather than form a normal middleware chain.
Important ideas
- Guards and inbound interceptors generally run global → controller → route.
- Outbound interceptors run route → controller → global.
- Filters start at the closest matching scope; the same error does not pass through every filter.
Reference: Nest request lifecycle.
- Keep ordering-dependent behavior explicit and verify it when multiple decorators or global registrations are involved.
Can you explain it without the notes?
How do global, controller and route handlers interact?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
Nest can attach request handlers at global, controller and route scopes. Scope determines which requests a handler applies to, while handler type determines execution order. Interceptors wrap inner work and unwind on the response path; exception filters select a matching handler rather than form a normal middleware chain.
Turn this concept into a clear answer.
- An interceptor cannot catch an earlier guard failure because it has not started wrapping the handler yet.
Adapted from 03_NESTJS.md · “How do global, controller and route handlers interact?”. Examples are study fragments; framework behavior can depend on your version.