Error Response Format
All error responses in the Blackjack API follow a consistent JSON structure defined by theErrorResponse class:
Response Fields
| Field | Type | Description |
|---|---|---|
timestamp | string (ISO 8601) | The exact time when the error occurred |
status | integer | HTTP status code |
code | string | Machine-readable error code for programmatic handling |
message | string | Human-readable error message with details |
path | string | The API endpoint path that generated the error |
Global Exception Handler
The API uses a centralized exception handling mechanism through theGlobalExceptionHandler class, which intercepts exceptions and converts them into standardized error responses.
HTTP Status Codes
The Blackjack API uses standard HTTP status codes to indicate the success or failure of requests:Success Codes
- 200 OK - Request succeeded
- 201 Created - New resource created successfully
Client Error Codes
- 400 Bad Request - Invalid input, validation error, or bad request format
- 404 Not Found - Requested resource (game or player) not found
- 409 Conflict - Invalid move or operation not allowed in current state
Server Error Codes
- 500 Internal Server Error - Unexpected server error
Error Response Examples
Resource Not Found (404)
When requesting a game or player that doesn’t exist:Validation Error (400)
When providing invalid input data:Business Logic Error (409)
When attempting an invalid game move:Internal Server Error (500)
When an unexpected error occurs:Error Handling Best Practices
Client Implementation
When integrating with the Blackjack API, implement error handling based on:- HTTP Status Code - For high-level error categorization
- Error Code - For specific error type handling
- Message - For logging and user-friendly error display
Example Error Handling
Reactive Error Handling
The Blackjack API is built using Spring WebFlux and returns reactiveMono types. Errors are propagated through the reactive stream and handled by the global exception handler, which returns error responses wrapped in Mono<ResponseEntity<ErrorResponse>>.