LESSON 07 / 18·2 min readIntermediate

How do global, controller and route handlers interact?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand 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.
PAUSE & RECALL

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.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • An interceptor cannot catch an earlier guard failure because it has not started wrapping the handler yet.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Guard vs pipe vs interceptor vs filter?

Adapted from 03_NESTJS.md · “How do global, controller and route handlers interact?”. Examples are study fragments; framework behavior can depend on your version.