ArgumentsHost

Abstraction over the handler arguments allowing transport-agnostic access in filters.

Since NestJS 10/11 Spec ↗

Syntax

host.switchToHttp() | host.switchToRpc() | host.switchToWs() | host.getType()

Returns

ArgumentsHost — An accessor for the underlying request context by transport.

Examples

import {
  Catch, ArgumentsHost, ExceptionFilter,
} from '@nestjs/common';

@Catch()
export class AllExceptionsFilter implements ExceptionFilter {
  catch(exception: unknown, host: ArgumentsHost) {
    if (host.getType() === 'http') {
      const res = host.switchToHttp().getResponse();
      res.status(500).json({ message: 'Internal error' });
    }
  }
}

Notes

getType() returns 'http', 'rpc', or 'ws' so a single filter can support multiple transports. ExecutionContext extends ArgumentsHost with handler and class accessors used by Reflector.