Loading…
Loading…
Documentation for the global exception handler, which provides a consistent, structured error response for all unhandled exceptions in the runtime service.
The GlobalRuntimeExceptionHandler is a system component that acts as a centralized, catch-all error handler for the API runtime service. Its primary purpose is to intercept any unexpected exceptions that are not handled by specific API endpoint logic.
This handler solves a critical problem: preventing unhandled exceptions from propagating to the underlying web framework, which would otherwise result in a generic, uninformative HTTP 500 error with an empty body. Instead, the GlobalRuntimeExceptionHandler ensures that every unexpected failure produces a standardized, structured JSON error response.
This component guarantees:
The handler operates on exceptions that escape from controller methods. It does not intercept successfully returned responses, including structured error responses that are intentionally returned by API logic (e.g., validation failures from the RuntimeController).
The GlobalRuntimeExceptionHandler is implemented as a RestControllerAdvice, allowing it to intercept exceptions from any controller within the runtime service. It contains logic to differentiate between various types of exceptions and respond accordingly.
flowchart TD
A[Exception escapes controller] --> B{Global Handler intercepts};
B --> C{Is it `UnboundTenantException`?};
C -- Yes --> D[Return HTTP 401 / S2R-RUN-0401];
C -- No --> E{Is it a Spring `ErrorResponse`?};
E -- Yes --> F[Rethrow to Spring default handler<br>(preserves 4xx status)];
E -- No --> G[Treat as unhandled internal error];
G --> H[Log full exception details internally];
H --> I[Return HTTP 500 / S2R-RUN-0500];The processing flow is as follows:
GlobalRuntimeExceptionHandler intercepts the exception.UnboundTenantException. If so, it signifies a request that requires tenant context was processed without one. The handler logs a warning and returns a specific HTTP 401 error.ErrorResponse. These exceptions are typically generated by the framework itself for issues like a non-existent route (404 Not Found) or an unsupported HTTP method (405 Method Not Allowed). The handler re-throws these exceptions, allowing Spring's default mechanism to handle them and preserve their original, correct HTTP 4xx status code.ERROR level along with the correlation ID.IMPORTANT
The handler's logic ensures that client-side errors (like a 404 Not Found) are not masked as server-side 500 errors. It carefully preserves the distinction by letting the framework handle its own ErrorResponse exceptions.
A correlation ID is used to link an error response received by an API consumer to the detailed diagnostic logs on the server. The ID is resolved as follows:
X-Correlation-Id header.The resulting correlation ID is included in both the X-Correlation-Id response header and the JSON error body.
When the handler generates an error, it returns a standard HTTP response with a specific body structure.
500 Internal Server Error: For generic, unhandled exceptions.401 Unauthorized: For UnboundTenantException.X-Correlation-Id: Contains the correlation ID for the request.This example shows the response for a generic unhandled exception.
{
"error": {
"code": "S2R-RUN-0500",
"message": "An unexpected internal error occurred",
"details": {
"path": "/some/api/endpoint"
},
"correlationId": "123e4567-e89b-12d3-a456-426614174000"
}
}
The response body is a JSON object containing a single top-level error key.
| Field | Type | Description |
|---|---|---|
error | Object | A container for all error details. |
error.code | String | A stable, machine-readable error code. See Troubleshooting for defined codes. |
error.message | String | A generic, human-readable description of the error. This message is stable and does not contain internal exception details. |
error.details | Object | An object containing additional, non-sensitive context about the error. |
error.details.path | String | The URI path of the API request that triggered the error. |
error.correlationId | String | The unique ID for this error event, matching the X-Correlation-Id response header. This should be provided to support teams when reporting an issue. |
The GlobalRuntimeExceptionHandler is not externally configurable. Its behavior, including error codes and messages, is defined by static constants within the service and cannot be modified via application properties or environment variables.
The handler produces the following distinct error codes.
| Code | HTTP Status | Message | Trigger |
|---|---|---|---|
S2R-RUN-0500 | 500 | An unexpected internal error occurred | An exception occurred during request processing that was not a framework-level ErrorResponse or a specific UnboundTenantException. This indicates an unexpected fault within the runtime service. |
S2R-RUN-0401 | 401 | Tenant authentication failed | An UnboundTenantException was thrown, indicating a request requiring a tenant context was processed without one. This typically points to an issue with the API consumer's authentication or tenant identification. |
NOTE
When you encounter an error, always provide the correlationId from the response body or the X-Correlation-Id header when seeking support. This allows operators to find the exact internal log entry corresponding to your failed request.
S2R-RUN-0401 error.