Challenge - 5 Problems
NestJS HTTP Exceptions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1: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?Attempts:
2 left
💡 Hint
Think about what 'Not Found' means in HTTP status codes.
✗ Incorrect
The NotFoundException in NestJS sends a 404 status code, which means the requested resource was not found.
📝 Syntax
intermediate1: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?Attempts:
2 left
💡 Hint
Remember how to create and throw exceptions in JavaScript/TypeScript.
✗ Incorrect
In NestJS, exceptions are classes. You must use new to create an instance and throw it.
❓ state_output
advanced2: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?Attempts:
2 left
💡 Hint
Check the default message and status code for UnauthorizedException.
✗ Incorrect
The default response body for UnauthorizedException includes statusCode 401 and message 'Unauthorized'.
🔧 Debug
advanced2:00remaining
Why does this NestJS code throw a runtime error?
Consider this code snippet in a controller method:
What is the cause of the runtime error?
throw new HttpException('Forbidden', 403);What is the cause of the runtime error?
Attempts:
2 left
💡 Hint
Check the NestJS HttpException constructor signature.
✗ Incorrect
The HttpException constructor accepts a message and a status code number like 403. This code is valid and does not cause a runtime error.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Think about the difference between 401 and 403 HTTP status codes.
✗ Incorrect
ForbiddenException corresponds to HTTP 403, meaning the user is authenticated but does not have permission.
UnauthorizedException means 401, the user is not authenticated.