Skip to content

Confirm error handling refactor addresses transaction rollback concerns#66

Closed
Copilot wants to merge 1 commit intoneverthrowfrom
copilot/sub-pr-62-another-one
Closed

Confirm error handling refactor addresses transaction rollback concerns#66
Copilot wants to merge 1 commit intoneverthrowfrom
copilot/sub-pr-62-another-one

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 3, 2026

Review response to feedback on PR #62 regarding error handling in handleCompleteHeat. The original code threw errors with _statusCode inside transactions, which the middleware didn't recognize, potentially resulting in incorrect status codes.

Changes Verified

The refactor in commit 2633248 correctly addresses the concern:

  • Transaction handling: Uses withResultTransaction wrapper that intercepts err() results and rolls back via sentinel value
  • Error propagation: Returns Result<T, E> from transaction instead of throwing
  • Status mapping: Checks txResult.isErr() outside transaction scope and uses getDomainErrorStatusCode to map domain errors to HTTP status codes

Before:

await db.transaction(async (tx) => {
  const result = await heatService.completeHeat(heatId, new Date());
  if (result.isErr()) {
    const status = getDomainErrorStatusCode(result.error);
    throw Object.assign(result.error, { _statusCode: status }); // ❌ Middleware ignores _statusCode
  }
});

After:

const txResult = await withResultTransaction(db, async (tx) => {
  return heatService.completeHeat(heatId, new Date());
});

if (txResult.isErr()) {
  const status = getDomainErrorStatusCode(txResult.error); // ✅ Explicit status mapping
  return createErrorResponse(txResult.error.message, status);
}

The implementation ensures transaction rollback on domain errors while preserving typed error information for proper HTTP status code mapping.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Make requested changes based on feedback on #62 Confirm error handling refactor addresses transaction rollback concerns Feb 3, 2026
Copilot AI requested a review from danbim February 3, 2026 09:45
@danbim danbim closed this Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants