@UseFilters()

Binds exception filters that catch and format errors thrown during request handling.

Since NestJS 10/11 Spec ↗

Syntax

@UseFilters(...filters: (ExceptionFilter | Type<ExceptionFilter>)[])

Parameters

NameTypeRequiredDescription
filters ExceptionFilter[] No Filter instances or classes that handle thrown exceptions.

Returns

ClassDecorator | MethodDecorator — A decorator applied at controller or handler level.

Examples

import { Controller, Get, UseFilters } from '@nestjs/common';
import { HttpExceptionFilter } from './http-exception.filter';

@Controller('cats')
@UseFilters(HttpExceptionFilter)
export class CatsController {
  @Get()
  find() {
    throw new Error('boom');
  }
}

Notes

Method-level filters override controller-level ones, which override the global filter. Use @Catch() on the filter class to scope which exception types it handles.