Error Code Overview
The Blackjack API uses specific error codes to identify different types of errors. Each error code is returned in thecode field of the error response.
Domain Exception Errors
These errors are thrown by the domain layer when business rules are violated.GAME_NOT_FOUND
HTTP Status: 404 Not FoundException Class:
GameNotFoundExceptionSource:
domain/exception/GameNotFoundException.java:4
Description
Thrown when attempting to access a game that doesn’t exist in the system.When It Occurs
- Retrieving game state with an invalid game ID
- Playing a move on a non-existent game
- Deleting a game that doesn’t exist
Example Response
Usage in Code
PLAYER_NOT_FOUND
HTTP Status: 404 Not FoundException Class:
PlayerNotFoundExceptionSource:
domain/exception/PlayerNotFoundException.java:4
Description
Thrown when attempting to access a player that doesn’t exist in the system.When It Occurs
- Changing the name of a non-existent player
- Retrieving player information with an invalid player ID
- Accessing player statistics or game history
Example Response
Usage in Code
INVALID_PLAYER_NAME
HTTP Status: 400 Bad RequestException Class:
InvalidPlayerNameExceptionSource:
domain/exception/InvalidPlayerNameException.java:4
Description
Thrown when a player name violates validation rules.Validation Rules
- Cannot be null
- Cannot be blank (empty or whitespace only)
- Maximum length: 30 characters
- Leading/trailing whitespace is trimmed
When It Occurs
- Creating a new game with an invalid player name
- Changing a player’s name to an invalid value
Example Responses
Empty Name:Usage in Code
INVALID_MOVE
HTTP Status: 409 ConflictException Class:
InvalidMoveExceptionSource:
domain/exception/InvalidMoveException.java:4
Description
Thrown when attempting to perform a game move that is not allowed in the current game state.When It Occurs
- Playing a move (HIT or STAND) when the game is not in progress
- Attempting to play after the game has finished
- Trying to make moves on a game that’s in PLAYER_WINS, DEALER_WINS, or PUSH status
Example Response
Usage in Code
Validation Errors
VALIDATION_ERROR
HTTP Status: 400 Bad RequestException Classes:
WebExchangeBindException, ConstraintViolationExceptionSource:
GlobalExceptionHandler.java:67, GlobalExceptionHandler.java:81
Description
Thrown when request data fails Spring validation constraints.When It Occurs
- Missing required fields in request body
- Invalid data types
- Constraint violations on DTOs
- Bean validation failures
Example Response
General Errors
BAD_REQUEST
HTTP Status: 400 Bad RequestException Class:
IllegalArgumentExceptionSource:
GlobalExceptionHandler.java:91
Description
Catch-all for illegal arguments and malformed requests.Example Response
INTERNAL_ERROR
HTTP Status: 500 Internal Server ErrorException Class:
Exception (generic)Source:
GlobalExceptionHandler.java:101
Description
Generic error for unexpected server-side exceptions. The actual error details are logged server-side but a generic message is returned to the client for security.Example Response
Error Code Summary Table
| Error Code | HTTP Status | Exception | Common Scenarios |
|---|---|---|---|
GAME_NOT_FOUND | 404 | GameNotFoundException | Invalid game ID in request |
PLAYER_NOT_FOUND | 404 | PlayerNotFoundException | Invalid player ID in request |
INVALID_PLAYER_NAME | 400 | InvalidPlayerNameException | Name validation failure |
INVALID_MOVE | 409 | InvalidMoveException | Move on finished game |
VALIDATION_ERROR | 400 | WebExchangeBindException, ConstraintViolationException | Request validation failure |
BAD_REQUEST | 400 | IllegalArgumentException | Malformed request |
INTERNAL_ERROR | 500 | Exception | Unexpected server error |
Handling Errors in Your Application
Check Error Codes
Always check thecode field to determine the specific error type:
User-Friendly Messages
Themessage field contains technical details. Consider mapping error codes to user-friendly messages: