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:
- catch(exception: HttpException, host: ArgumentsHost) {
- const ctx = host.switchToHttp();
- const response = ctx.getResponse();
- response.status(exception.getStatus()).json({ statusCode: exception.getStatus() });
- }