Differentiate exception types for 400/404/409
Type: API behavior
Priority: P1
Summary
All failures throw IllegalStateException, losing HTTP semantics.
Impact
Clients get 500s instead of correct 4xx.
Evidence
bookCommandUseCases.java lines 25, 29, 34.
if (shelfAssignmentRequest == null || shelfAssignmentRequest.shelfId() == null) {
throw new IllegalStateException("Shelf id is required");
}
if (!shelfAccessPort.findShelfById(shelfAssignmentRequest.shelfId()).isPresent()) {
throw new IllegalStateException(
"Shelf not found with id: " + shelfAssignmentRequest.shelfId());
}
if (shelfAccessPort.isFull(shelfAssignmentRequest.shelfId())) {
throw new IllegalStateException(
"Shelf with id " + shelfAssignmentRequest.shelfId() + " is full");
}
Proposed Fix
Use IllegalArgumentException for bad input, NotFound for missing shelf, Conflict for full shelf; map with @ControllerAdvice.
Acceptance Criteria
- Invalid input → 400
- Missing shelf → 404
- Full shelf → 409
Expected
Errors map to 400 (bad input), 404 (not found), 409 (conflict).
Actual
All failures throw IllegalStateException and surface as 500 without mapping.
Differentiate exception types for 400/404/409
Type: API behavior
Priority: P1
Summary
All failures throw
IllegalStateException, losing HTTP semantics.Impact
Clients get 500s instead of correct 4xx.
Evidence
bookCommandUseCases.javalines 25, 29, 34.Proposed Fix
Use
IllegalArgumentExceptionfor bad input,NotFoundfor missing shelf,Conflictfor full shelf; map with@ControllerAdvice.Acceptance Criteria
Expected
Errors map to 400 (bad input), 404 (not found), 409 (conflict).
Actual
All failures throw IllegalStateException and surface as 500 without mapping.