Card 04/ 07
All 7 cards
ComparisonDifficulty: Intermediate1 min
Which Exception, Which Status
A status code is a claim about what happened, and the exception that triggered it should match that claim — not just be whatever was easiest to throw at the time.
| What happened | Status | Custom exception example |
|---|---|---|
| The resource doesn't exist | 404 Not Found | RideNotFoundException |
| The request itself is malformed or fails validation | 400 Bad Request | MethodArgumentNotValidException (built in) |
| The caller isn't authenticated | 401 Unauthorized | AuthenticationException-family |
| The resource exists but conflicts with the request | 409 Conflict | DuplicateRideException |
The rule that decides each row: 404 means the lookup failed, 400 means the request was never valid to begin with, and 409 means the request was valid but collided with something that already exists. A caller reading the status code alone should be able to tell which of these three happened.