Challenge - 5 Problems
Problem Details Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Spring Boot error response?
Given a REST controller that throws a
ResponseStatusException with status 404 and a custom message, what will the JSON error response contain when using Spring Boot's default Problem Details format?Spring Boot
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "User not found");Attempts:
2 left
💡 Hint
Look for the standard keys defined by RFC 7807 in the JSON response.
✗ Incorrect
Spring Boot uses the Problem Details format (RFC 7807) by default for error responses. It includes keys like type, title, status, and detail.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly creates a Problem Details response in Spring Boot?
You want to return a custom Problem Details JSON response with status 400 and a detail message. Which code snippet correctly uses Spring Boot's
ProblemDetail class?Attempts:
2 left
💡 Hint
Check the official Spring Boot 3 method to create ProblemDetail instances.
✗ Incorrect
The ProblemDetail.forStatusAndDetail static method is the correct way to create a ProblemDetail with status and detail.
🔧 Debug
advanced2:00remaining
Why does this custom error handler not return Problem Details JSON?
A developer wrote this exception handler method but the response is plain text instead of Problem Details JSON. What is the likely cause?
Spring Boot
@ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public String handleBadRequest(IllegalArgumentException ex) { return ex.getMessage(); }
Attempts:
2 left
💡 Hint
Consider how Spring decides the response content type based on return type.
✗ Incorrect
Returning a String causes Spring to treat the response as plain text. To return Problem Details JSON, the method should return a ProblemDetail object or ResponseEntity<ProblemDetail>.
🧠 Conceptual
advanced1:30remaining
What is the purpose of the 'type' field in Problem Details JSON?
In the Problem Details standard error format, what does the
type field represent?Attempts:
2 left
💡 Hint
Think about how clients can learn more about the error type.
✗ Incorrect
The type field is a URI that points to documentation about the error type, helping clients understand the problem.
❓ state_output
expert2:30remaining
What is the JSON output of this Spring Boot controller advice method?
Given this controller advice method, what JSON will be returned when a
NullPointerException occurs?Spring Boot
@ControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(NullPointerException.class) public ResponseEntity<ProblemDetail> handleNullPointer(NullPointerException ex) { ProblemDetail pd = ProblemDetail.forStatusAndDetail(HttpStatus.INTERNAL_SERVER_ERROR, "Null value encountered"); pd.setType(URI.create("https://example.com/errors/null-pointer")); pd.setTitle("Null Pointer Exception"); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(pd); } }
Attempts:
2 left
💡 Hint
Check how the ProblemDetail fields are set explicitly in the method.
✗ Incorrect
The method sets a custom type URI and title, so the JSON reflects those values along with status and detail.