Nestjs interceptors
Skill dkmqflx/nestjs-best-practices-plugin/plugins/nestjs-best-practices/skills/nestjs-interceptors
Claude Code plugin: 12 NestJS best-practice skills (90 rules) grounded in the official NestJS docs
npx -y skills add dkmqflx/nestjs-best-practices-plugin --skill nestjs-interceptorsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
NestJS interceptors best practices. Use when writing or reviewing NestJS interceptors — response transformation, logging, timeouts, or caching around handlers. Triggers on NestInterceptor, intercept(), CallHandler, map(), or @UseInterceptors.
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
2.5 KB, as published. Nobody here has run it
NestJS Interceptors
Interceptors are @Injectable() classes implementing NestInterceptor. Their
intercept(context: ExecutionContext, next: CallHandler) method runs logic
before the route handler and transforms the response stream returned by
next.handle() using RxJS operators. They are the idiomatic place for
cross-cutting concerns — response shaping, logging, timeouts, caching — that
should stay out of controllers and services.
When to Apply
Apply these rules when you are:
- Writing or reviewing a class that implements
NestInterceptor. - Wrapping handler responses in a consistent envelope.
- Adding request/response logging or latency measurement.
- Enforcing per-request timeouts.
- Caching GET responses with
CacheInterceptor. - Deciding whether to bind an interceptor globally, per-controller, or per-route.
Do not reach for an interceptor when the work is core business logic — that
belongs in a service (see interceptors-not-for-mutation-logic).
Rules
| Rule | Impact | Summary |
|---|---|---|
| response-transform-interceptor | HIGH | Wrap responses in a consistent envelope via map(). |
| logging-interceptor | MEDIUM | Measure handler duration with tap(); log method/url/time. |
| timeout-interceptor | HIGH | Fail slow requests with timeout() + RequestTimeoutException. |
| cache-interceptor | MEDIUM | Cache GET responses with CacheInterceptor + CacheModule. |
| interceptors-not-for-mutation-logic | HIGH | Keep business logic in services; interceptors are cross-cutting only. |
| bind-globally-vs-scoped | MEDIUM | Prefer APP_INTERCEPTOR for DI-friendly global binding. |
How to Use
- Identify the cross-cutting concern (transform, log, timeout, cache).
- Open the matching rule file and follow the Correct pattern.
- Keep
intercept()thin — pipe RxJS operators ontonext.handle(), never put domain logic inside. - Choose a binding scope with
bind-globally-vs-scoped: route, controller, or global viaAPP_INTERCEPTOR.