Description
The DELETE /v1/organizations/{org}/ledgers/{ledger}/operation-routes/{id} endpoint returns 204 No Content when the provided operation route UUID does not exist. The expected behavior is 404 Not Found with error code 0101 (Operation Route Not Found).
Root Cause
In components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql.go, the Delete method performs a soft delete via:
if _, err := db.ExecContext(ctx, query, args...); err != nil {
The sql.Result is discarded (_), so RowsAffected() is never checked. When the UUID does not exist, the UPDATE affects 0 rows but returns no error, causing the handler to return 204.
Expected Behavior
When deleting a non-existent operation route, the API should return:
- HTTP 404
- Error code:
0101
- Title:
Operation Route Not Found
Suggested Fix
Capture the sql.Result, call RowsAffected(), and return services.ErrDatabaseItemNotFound when the count is 0. The command layer already handles this error correctly and maps it to the appropriate 404 response.
result, err := db.ExecContext(ctx, query, args...)
if err != nil {
// existing error handling
}
rowsAffected, _ := result.RowsAffected()
if rowsAffected == 0 {
return services.ErrDatabaseItemNotFound
}
Description
The
DELETE /v1/organizations/{org}/ledgers/{ledger}/operation-routes/{id}endpoint returns 204 No Content when the provided operation route UUID does not exist. The expected behavior is 404 Not Found with error code0101(Operation Route Not Found).Root Cause
In
components/ledger/internal/adapters/postgres/operationroute/operationroute.postgresql.go, theDeletemethod performs a soft delete via:The
sql.Resultis discarded (_), soRowsAffected()is never checked. When the UUID does not exist, the UPDATE affects 0 rows but returns no error, causing the handler to return 204.Expected Behavior
When deleting a non-existent operation route, the API should return:
0101Operation Route Not FoundSuggested Fix
Capture the
sql.Result, callRowsAffected(), and returnservices.ErrDatabaseItemNotFoundwhen the count is 0. The command layer already handles this error correctly and maps it to the appropriate 404 response.