Skip to content

What's new in 0.2.2

0.2.2 changes how the exception filters of @nestjs-pipeline/zod, /casl, /feature-flags, /idempotency and /rate-limit answer, so that one code path serves Express and Fastify. Registering them needs a change, and the five packages add a @nestjs/core ^11.0.0 peer.

Exception filters reply through Nest’s HTTP adapter

Section titled “Exception filters reply through Nest’s HTTP adapter”

ZodValidationFilter, UnauthorizedActionFilter, FeatureDisabledFilter, IdempotencyConflictFilter and RateLimitExceededFilter take Nest’s HttpAdapterHost and answer with httpAdapter.reply (RateLimitExceededFilter also sets Retry-After through the adapter). On Fastify, an error thrown in Nest middleware reaches a filter with the raw Node response; the filters answer it too, instead of throwing and leaving the request without a response.

Register each filter as a provider, so Nest injects the host:

import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { ZodValidationFilter } from '@nestjs-pipeline/zod';
@Module({
providers: [{ provide: APP_FILTER, useClass: ZodValidationFilter }],
})
export class AppModule {}

or pass it in main.ts: app.useGlobalFilters(new ZodValidationFilter(app.get(HttpAdapterHost))). A filter built without the host (new ZodValidationFilter()) does not compile. FeatureDisabledFilter takes its options as the second argument: new FeatureDisabledFilter(app.get(HttpAdapterHost), options).