The Products API uses a singleDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ricpalomino/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
@ControllerAdvice class, GlobalExceptionHandler, to intercept every unhandled exception before it reaches the client. Instead of letting Spring’s default error page or a bare stack trace escape over the wire, GlobalExceptionHandler converts each exception into a structured ApiResponse JSON object with a machine-readable responseCode, a human-readable responseMessage, and an optional data payload. This means every error response your client receives has the same shape as a successful one.
ApiResponse envelope
All responses—success and error—are wrapped in the sameApiResponse<T> type:
data null, or pass a Map<String, String> of field-level errors for validation failures.
GlobalExceptionHandler
@Hidden annotation prevents this class from appearing in the OpenAPI/Swagger UI output, keeping the API reference clean.
Exception handlers
404 Not Found — ProductNotFoundException
404 Not Found — ProductNotFoundException
ProductNotFoundException is thrown by the service layer whenever a requested product ID does not exist in the repository.WARN-level message and returns HTTP 404 with the exception’s message as responseMessage:400 Bad Request — MethodArgumentNotValidException
400 Bad Request — MethodArgumentNotValidException
When a controller method is annotated with Multiple fields can fail simultaneously, and the
@Valid and the incoming request body fails Jakarta Bean Validation, Spring throws MethodArgumentNotValidException. The handler extracts all field-level errors from BindingResult and places them in the data map so the client knows exactly which fields need correction.data map will contain one entry per failing field.500 Internal Server Error — catch-all
500 Internal Server Error — catch-all
Any exception not matched by the two handlers above falls through to the generic
Exception handler. The full stack trace is logged at ERROR level (and written to logs/error.log by the dedicated error appender), but only a generic message is returned to the client to avoid leaking implementation details.Response reference
| HTTP status | responseCode | Trigger | data |
|---|---|---|---|
| 200 OK | "200" | Successful operation | Resource or list |
| 404 Not Found | "404" | Product ID not found | null |
| 400 Bad Request | "400" | Bean Validation failure | Map<field, message> |
| 500 Internal Server Error | "500" | Any unhandled exception | null |
Throwing ProductNotFoundException
ThrowProductNotFoundException from the service layer when a lookup by ID returns no result:
GlobalExceptionHandler picks it up automatically. You do not need any try-catch in the controller.