What is the purpose of the Problem Details standard format in Spring Boot?
It provides a consistent way to return error information in HTTP responses, making it easier for clients to understand and handle errors.
Click to reveal answer
beginner
Which HTTP status code is commonly used with Problem Details responses?
Status codes like 400 (Bad Request), 404 (Not Found), and 500 (Internal Server Error) are commonly used with Problem Details to indicate the error type.
Click to reveal answer
intermediate
Name the key JSON fields defined in the Problem Details format.
The key fields are: type (URI identifying the error type), title (short summary), status (HTTP status code), detail (detailed message), and instance (URI identifying the specific occurrence).
Click to reveal answer
intermediate
How can you customize the Problem Details response in Spring Boot?
You can create a custom ProblemDetail object or extend the default error handling by implementing ErrorAttributes or using @ExceptionHandler methods to set custom fields.
Click to reveal answer
beginner
Why is using Problem Details format better than plain error messages?
It standardizes error responses, making them machine-readable and easier to parse, which improves client-side error handling and debugging.
Click to reveal answer
What field in Problem Details contains a short, human-readable summary of the error?
Ainstance
Btype
Cstatus
Dtitle
✗ Incorrect
The title field provides a brief, human-readable summary of the problem.
Which Spring Boot class represents the Problem Details error format?
AErrorAttributes
BErrorResponse
CProblemDetail
DResponseEntity
✗ Incorrect
Spring Boot uses the ProblemDetail class to represent the standard error format.
What HTTP status code is NOT typically associated with Problem Details errors?
A404
B200
C400
D500
✗ Incorrect
Status code 200 means success and is not used for error responses.
Which field in Problem Details identifies the specific occurrence of the problem?
Ainstance
Btype
Cdetail
Dstatus
✗ Incorrect
The instance field is a URI that identifies the specific occurrence of the problem.
How can you add custom information to a Problem Details response in Spring Boot?
ABy extending the ProblemDetail object or customizing ErrorAttributes
BBy changing the HTTP status code only
CBy modifying the request headers
DBy using plain text responses
✗ Incorrect
Customizing the ProblemDetail object or ErrorAttributes allows adding extra fields or details.
Explain the main fields of the Problem Details format and their purpose.
Think about what each field tells the client about the error.
You got /5 concepts.
Describe how Spring Boot supports and customizes the Problem Details error format.
Consider how you can change the error response content.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using Problem Details in Spring Boot APIs?
easy
A. To standardize error messages for better clarity and consistency
B. To speed up API response times
C. To encrypt API responses for security
D. To generate API documentation automatically
Solution
Step 1: Understand the role of Problem Details
Problem Details format is designed to provide a consistent structure for error messages in APIs.
Step 2: Identify the main benefit
This standardization helps clients understand errors clearly and handle them properly.
Final Answer:
To standardize error messages for better clarity and consistency -> Option A
Quick Check:
Standard error format = clarity [OK]
Hint: Problem Details = clear, consistent error messages [OK]
Common Mistakes:
Thinking it improves speed
Confusing with security features
Assuming it auto-generates docs
2. Which of the following fields is NOT part of the standard Problem Details JSON format?
easy
A. type
B. title
C. timestamp
D. status
Solution
Step 1: Recall standard Problem Details fields
The standard fields include type, title, status, detail, and instance.
Step 2: Identify the incorrect field
Timestamp is not part of the official Problem Details specification.
Final Answer:
timestamp -> Option C
Quick Check:
Standard fields exclude timestamp [OK]
Hint: Remember standard fields: type, title, status, detail, instance [OK]
Common Mistakes:
Confusing timestamp with instance
Assuming all error info fields are standard
Mixing with custom fields
3. Given this Spring Boot controller snippet, what will be the HTTP status code in the Problem Details response when ResourceNotFoundException is thrown?
@RestController
public class MyController {
@GetMapping("/item/{id}")
public Item getItem(@PathVariable String id) {
throw new ResourceNotFoundException("Item not found");
}
}
medium
A. 404 Not Found
B. 200 OK
C. 500 Internal Server Error
D. 400 Bad Request
Solution
Step 1: Understand exception mapping in Spring Boot
ResourceNotFoundException typically maps to HTTP 404 status to indicate missing resource.
Step 2: Confirm standard error status for not found
Spring Boot's default error handling returns 404 for resource not found exceptions.
Final Answer:
404 Not Found -> Option A
Quick Check:
Resource missing = 404 [OK]
Hint: Resource not found usually means 404 status [OK]
Common Mistakes:
Assuming 200 OK on exception
Confusing 400 with 404
Thinking all exceptions return 500
4. You wrote a custom exception handler to return Problem Details but the API returns a plain error message instead. What is the most likely cause?
medium
A. The exception class does not extend RuntimeException
B. The controller method is not annotated with @GetMapping
C. The application.properties file is missing
D. The handler method is missing @ExceptionHandler annotation
Solution
Step 1: Check exception handler setup
Custom handlers must use @ExceptionHandler to catch exceptions and format responses.
Step 2: Identify missing annotation impact
Without @ExceptionHandler, Spring Boot won't invoke the handler, so default error response is sent.
Final Answer:
The handler method is missing @ExceptionHandler annotation -> Option D
Quick Check:
@ExceptionHandler missing = no custom error [OK]
Hint: Always add @ExceptionHandler to custom error methods [OK]