7.1 Default Exception Handling Mechanism
When an exception occurs during the execution of an application, Spring Boot provides a basic error handling mechanism (BasicErrorController) that detects and handles it, even if the developer hasn't made any special configurations.
Whitelabel Error Page
When an exception is thrown from an endpoint or a status like 404 Not Found occurs, a default HTML response called the Whitelabel Error Page is provided to the user accessing via a browser. This serves to hide the Tomcat stack trace screen.
Default Response Structure in REST API
If the client sends an API request including the Accept: application/json header, Spring Boot outputs an error response in JSON format like the one below, instead of HTML.
{
"timestamp": "2026-03-14T03:00:00.000+00:00",
"status": 500,
"error": "Internal Server Error",
"path": "/api/users"
}
This default response object contains the time of occurrence, status, error type, and the path where it occurred, making it very useful for early development.
Limitations of Default Handling
However, as a service becomes more advanced, relying only on Spring's default configuration will hit limitations.
- Lack of Consistency: From the client's (frontend) perspective, the JSON structure of a normal response and the JSON structure of an error response are different, making it difficult to implement unified error handling.
- Lack of Business Context: It's difficult to subdivide and communicate delicate exception situations rejected by business rules, such as "permission error," "insufficient balance," or "product out of stock," using only a single HTTP status code (like
400or500). - Exposure of Unnecessary Information: Sometimes there is a risk of exposing the internal stack trace logged in the console as a response object, which is bad for security.
Therefore, in practice, a Global Exception Handling system based on Spring's @RestControllerAdvice is built to return error responses in a unified format agreed upon with the frontend.