NestJS · Middle · Question 6 of 75

What does an interceptor's intercept(context, next) return?

intercept(context: ExecutionContext, next: CallHandler) {
  const start = Date.now();
  return next.handle().pipe(tap(() => console.log(Date.now() - start)));
}

Explanation

If you don't call next.handle(), the handler never runs. That's how caching interceptors return stored responses.

Further reading

Problem with a question

NestJS · Middle · question 6

Test yourself

Take the NestJS · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz