0
0
NestJSframework~10 mins

Built-in HTTP exceptions in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to throw a 404 Not Found exception in a NestJS controller.

NestJS
throw new [1]();
Drag options to blanks, or click blank then click option'
ANotFoundException
BBadRequestException
CUnauthorizedException
DForbiddenException
Attempts:
3 left
💡 Hint
Common Mistakes
Using BadRequestException instead of NotFoundException.
Confusing UnauthorizedException with NotFoundException.
2fill in blank
medium

Complete the code to import the built-in HTTP exceptions from NestJS.

NestJS
import { [1] } from '@nestjs/common';
Drag options to blanks, or click blank then click option'
AInjectable
BController
CModule
DHttpException
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Controller or Module instead of HttpException.
Forgetting to import from '@nestjs/common'.
3fill in blank
hard

Fix the error in throwing a 400 Bad Request exception with a custom message.

NestJS
throw new [1]('Invalid input');
Drag options to blanks, or click blank then click option'
ANotFoundException
BBadRequestException
CUnauthorizedException
DForbiddenException
Attempts:
3 left
💡 Hint
Common Mistakes
Using NotFoundException for bad input errors.
Using UnauthorizedException for validation errors.
4fill in blank
hard

Fill both blanks to throw a 403 Forbidden exception with a custom message.

NestJS
throw new [1]('[2]');
Drag options to blanks, or click blank then click option'
AForbiddenException
BUnauthorized
CBadRequestException
DNotFoundException
Attempts:
3 left
💡 Hint
Common Mistakes
Using UnauthorizedException instead of ForbiddenException for 403 errors.
Not providing a message string.
5fill in blank
hard

Fill all three blanks to throw a 401 Unauthorized exception with a custom message and import it correctly.

NestJS
import { [1] } from '@nestjs/common';

throw new [2]('[3]');
Drag options to blanks, or click blank then click option'
AUnauthorizedException
BForbiddenException
CBad credentials
DNotFoundException
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong exception class.
Using a message that does not explain the error.