0
0
NestJSframework~20 mins

Built-in HTTP exceptions in NestJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NestJS HTTP Exceptions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:00remaining
What is the HTTP status code returned by NotFoundException in NestJS?
In NestJS, when you throw new NotFoundException(), what HTTP status code does the framework send back to the client?
A404
B403
C500
D200
Attempts:
2 left
💡 Hint
Think about what 'Not Found' means in HTTP status codes.
📝 Syntax
intermediate
1:30remaining
Which option correctly throws a BadRequestException with a custom message in NestJS?
You want to throw a BadRequestException with the message 'Invalid input data'. Which code snippet is correct?
Athrow new BadRequestException(); 'Invalid input data';
Bthrow new BadRequestException('Invalid input data');
Cthrow BadRequestException('Invalid input data');
DBadRequestException('Invalid input data');
Attempts:
2 left
💡 Hint
Remember how to create and throw exceptions in JavaScript/TypeScript.
state_output
advanced
2:00remaining
What is the response body when UnauthorizedException is thrown without a custom message?
In NestJS, if you throw new UnauthorizedException() without any message, what JSON response body will the client receive?
A{"statusCode":401,"message":"Unauthorized"}
B{"statusCode":401,"message":"Access denied"}
C{"statusCode":403,"message":"Unauthorized"}
D{"statusCode":400,"message":"Unauthorized"}
Attempts:
2 left
💡 Hint
Check the default message and status code for UnauthorizedException.
🔧 Debug
advanced
2:00remaining
Why does this NestJS code throw a runtime error?
Consider this code snippet in a controller method:
throw new HttpException('Forbidden', 403);

What is the cause of the runtime error?
AThe second argument must be an object, not a number.
BThe status code must be a string, not a number.
CThe second argument must be an enum or HttpStatus constant, not a raw number.
DThe second argument must be an HttpStatus enum value or number, but 403 is valid so no error.
Attempts:
2 left
💡 Hint
Check the NestJS HttpException constructor signature.
🧠 Conceptual
expert
2:30remaining
Which built-in NestJS HTTP exception class should you use to indicate a request is forbidden due to lack of permissions?
You want to respond with an HTTP status code that means the user is authenticated but not allowed to access the resource. Which NestJS exception class is the best choice?
AUnauthorizedException
BBadRequestException
CForbiddenException
DNotFoundException
Attempts:
2 left
💡 Hint
Think about the difference between 401 and 403 HTTP status codes.