Skip to content

Differentiate exception types for 400/404/409 #308

@leodvincci

Description

@leodvincci

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions