Skip to content

fix(billing): propagate upstream status from tx-signer errors#3039

Open
ygrishajev wants to merge 1 commit intomainfrom
fix/billing-propagate-tx-signer-upstream-status
Open

fix(billing): propagate upstream status from tx-signer errors#3039
ygrishajev wants to merge 1 commit intomainfrom
fix/billing-propagate-tx-signer-upstream-status

Conversation

@ygrishajev
Copy link
Copy Markdown
Contributor

@ygrishajev ygrishajev commented Apr 2, 2026

Why

When the tx-signer returns a 5xx error (e.g. 502), the API wraps it in a plain Error losing the status code. The error handler then defaults to 500, making it impossible to distinguish upstream failures from internal API errors.

What

  • ExternalSignerHttpSdkService: preserve the original AxiosError as cause when rethrowing
  • ChainErrorService: extract upstream status from error.cause when no chain error clue matches — 5xx statuses are propagated as-is, 4xx are left unhandled
  • Added 4 tests covering 502, 503, 4xx, and non-Axios cause scenarios

Summary by CodeRabbit

  • Tests

    • Added comprehensive test cases for error handling scenarios, validating upstream HTTP status code detection and error classification for gateway and service availability conditions.
  • Chores

    • Enhanced error propagation in billing and signing services to preserve original error context throughout the system, improving error tracking and diagnostic capabilities.

Preserve AxiosError as cause when ExternalSignerHttpSdkService rethrows
so ChainErrorService can extract the upstream status code. 5xx responses
from the tx-signer are now returned as-is instead of falling through
to 500.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Caution

Review failed

An error occurred during the review process. Please try again later.

📝 Walkthrough

Walkthrough

These changes enhance error handling in the billing services by introducing upstream HTTP status code extraction from error causes. A new helper method extracts 5xx status codes from nested Axios errors, transforming them into appropriate HTTP error objects. Error propagation is updated to preserve original error causes throughout the call chain, with comprehensive test coverage for the new transformation logic.

Changes

Cohort / File(s) Summary
Error Transformation Logic
apps/api/src/billing/services/chain-error/chain-error.service.ts
Added private method getUpstreamStatusFromCause() to extract upstream HTTP status from nested Axios errors. toAppError() now creates http-errors instances for 5xx upstream statuses instead of returning original errors.
Test Coverage
apps/api/src/billing/services/chain-error/chain-error.service.spec.ts
Extended test suite with cases validating toAppError behavior: returns BadGateway for 502, ServiceUnavailable for 5xx (503), returns original error for 4xx and non-Axios causes.
Error Propagation
apps/api/src/billing/services/external-signer-http-sdk/external-signer-http-sdk.service.ts
Updated error throwing to preserve original error as cause in both Axios and non-Axios error branches, enabling downstream error transformation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A chain of errors, now traced back with care,
Where upstream troubles float through the air,
The cause preserved, passed down the chain,
Five-hundred errors transform, not in vain,
Tests hop along to keep logic quite sane! 🔗

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically summarizes the main change: propagating upstream HTTP status codes from tx-signer errors through the billing service stack.
Description check ✅ Passed The description fully follows the template structure with clear 'Why' and 'What' sections explaining the problem, solution, and changes made without breaking changes or database migrations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/billing-propagate-tx-signer-upstream-status

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.81%. Comparing base (59a50eb) to head (296cf8b).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3039      +/-   ##
==========================================
- Coverage   59.63%   58.81%   -0.83%     
==========================================
  Files        1034      996      -38     
  Lines       24248    23357     -891     
  Branches     6009     5873     -136     
==========================================
- Hits        14461    13738     -723     
+ Misses       8536     8380     -156     
+ Partials     1251     1239      -12     
Flag Coverage Δ *Carryforward flag
api 81.26% <100.00%> (-0.01%) ⬇️
deploy-web 43.24% <ø> (ø) Carriedforward from 59a50eb
log-collector ?
notifications 86.06% <ø> (ø) Carriedforward from 59a50eb
provider-console 81.48% <ø> (ø) Carriedforward from 59a50eb
provider-proxy 85.21% <ø> (ø) Carriedforward from 59a50eb
tx-signer ?

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...illing/services/chain-error/chain-error.service.ts 100.00% <100.00%> (ø)
...igner-http-sdk/external-signer-http-sdk.service.ts 93.75% <100.00%> (ø)

... and 39 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants