Click in order · NestJS course · Module 2: Routing and Request Lifecycle

Structure of the catch Method in a Filter

Arrange the parts of an exception filter's catch() method in the correct order:

Items to click

  • const response = ctx.getResponse();
  • response.status(exception.getStatus()).json({ statusCode: exception.getStatus() });
  • }
  • catch(exception: HttpException, host: ArgumentsHost) {
  • const ctx = host.switchToHttp();
Show the answer

Correct order:

  1. catch(exception: HttpException, host: ArgumentsHost) {
  2. const ctx = host.switchToHttp();
  3. const response = ctx.getResponse();
  4. response.status(exception.getStatus()).json({ statusCode: exception.getStatus() });
  5. }