Skip to content

DELETE operation route returns 204 instead of 404 for non-existent UUID #2010

@gandalf-at-lerian

Description

@gandalf-at-lerian

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions