Problem: Both handlers throw ArgumentException("Trail with ID {id} not found") when no row matches. TrailsController maps every ArgumentException to 400 Bad Request ("Invalid trail ID format"), so:
Clients can't distinguish malformed id (400) from missing trail (404)
The NotFound branch in the controller is effectively dead code
API consumers can't reliably retry vs handle missing resources
Fix:
Either return null (use TrailDto? and let the controller map null to 404)
Or throw a dedicated NotFoundException (or domain-specific equivalent) that the controller maps to 404
Reserve ArgumentException for genuinely invalid id format
Acceptance criteria:
GET /api/Trails/{id} with malformed id returns 400
GET /api/Trails/{id} with valid id format but no match returns 404
PUT /api/Trails/{id} for non-existent id returns 404
Unit tests for both branches
**Severity:** High (REST contract correctness)
**Files:**
- `SpikerSoft.Business/Domain/Map/Trails/Queries/GetTrailById/GetTrailByIdQueryHandler.cs` (~24-38)
- `SpikerSoft.Business/Domain/Map/Trails/Commands/UpdateTrail/UpdateTrailCommandHandler.cs` (~32-38)
**Problem:** Both handlers throw `ArgumentException("Trail with ID {id} not found")` when no row matches. `TrailsController` maps every `ArgumentException` to **400 Bad Request** ("Invalid trail ID format"), so:
- Clients can't distinguish malformed id (400) from missing trail (404)
- The `NotFound` branch in the controller is effectively dead code
- API consumers can't reliably retry vs handle missing resources
**Fix:**
- Either return `null` (use `TrailDto?` and let the controller map null to 404)
- Or throw a dedicated `NotFoundException` (or domain-specific equivalent) that the controller maps to 404
- Reserve `ArgumentException` for genuinely invalid id format
**Acceptance criteria:**
- [ ] GET /api/Trails/{id} with malformed id returns 400
- [ ] GET /api/Trails/{id} with valid id format but no match returns 404
- [ ] PUT /api/Trails/{id} for non-existent id returns 404
- [ ] Unit tests for both branches
Introduced TrailNotFoundException (in SpikerSoft.Business/Domain/Map/Trails/Exceptions/). GetTrailByIdQueryHandler and UpdateTrailCommandHandler now throw it instead of ArgumentException when the row is missing. TrailsController catches TrailNotFoundException first and returns 404; ArgumentException continues to map to 400 for genuinely malformed ids.
**Resolved.**
Introduced `TrailNotFoundException` (in `SpikerSoft.Business/Domain/Map/Trails/Exceptions/`). `GetTrailByIdQueryHandler` and `UpdateTrailCommandHandler` now throw it instead of `ArgumentException` when the row is missing. `TrailsController` catches `TrailNotFoundException` first and returns 404; `ArgumentException` continues to map to 400 for genuinely malformed ids.
Files changed:
- `SpikerSoft.Business/Domain/Map/Trails/Exceptions/TrailNotFoundException.cs` (new)
- `SpikerSoft.Business/Domain/Map/Trails/Queries/GetTrailById/GetTrailByIdQueryHandler.cs`
- `SpikerSoft.Business/Domain/Map/Trails/Commands/UpdateTrail/UpdateTrailCommandHandler.cs`
- `SpikerSoft.Api/Domain/Map/Trails/TrailsController.cs`
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Severity: High (REST contract correctness)
Files:
SpikerSoft.Business/Domain/Map/Trails/Queries/GetTrailById/GetTrailByIdQueryHandler.cs(~24-38)SpikerSoft.Business/Domain/Map/Trails/Commands/UpdateTrail/UpdateTrailCommandHandler.cs(~32-38)Problem: Both handlers throw
ArgumentException("Trail with ID {id} not found")when no row matches.TrailsControllermaps everyArgumentExceptionto 400 Bad Request ("Invalid trail ID format"), so:NotFoundbranch in the controller is effectively dead codeFix:
null(useTrailDto?and let the controller map null to 404)NotFoundException(or domain-specific equivalent) that the controller maps to 404ArgumentExceptionfor genuinely invalid id formatAcceptance criteria:
Resolved.
Introduced
TrailNotFoundException(inSpikerSoft.Business/Domain/Map/Trails/Exceptions/).GetTrailByIdQueryHandlerandUpdateTrailCommandHandlernow throw it instead ofArgumentExceptionwhen the row is missing.TrailsControllercatchesTrailNotFoundExceptionfirst and returns 404;ArgumentExceptioncontinues to map to 400 for genuinely malformed ids.Files changed:
SpikerSoft.Business/Domain/Map/Trails/Exceptions/TrailNotFoundException.cs(new)SpikerSoft.Business/Domain/Map/Trails/Queries/GetTrailById/GetTrailByIdQueryHandler.csSpikerSoft.Business/Domain/Map/Trails/Commands/UpdateTrail/UpdateTrailCommandHandler.csSpikerSoft.Api/Domain/Map/Trails/TrailsController.cs