Skip to content

feat: map Horizon error codes to HTTP status codes#238

Merged
Sulex45 merged 1 commit into
stellarkit-lab-devtools:mainfrom
AlphaMaleBaDI:feature/horizon-status-mapper
Jun 2, 2026
Merged

feat: map Horizon error codes to HTTP status codes#238
Sulex45 merged 1 commit into
stellarkit-lab-devtools:mainfrom
AlphaMaleBaDI:feature/horizon-status-mapper

Conversation

@AlphaMaleBaDI
Copy link
Copy Markdown
Contributor

Closes #222

Summary

Adds a centralized Horizon error code to HTTP status mapper and integrates it into the API error handling pipeline.

Changes

  • Added src/utils/horizonStatusMapper.js
  • Mapped common Horizon transaction and operation result codes to semantically appropriate HTTP status codes
  • Integrated mapper into src/middleware/errorHandler.js
  • Added dedicated unit tests for the mapper utility
  • Added middleware tests covering Horizon error handling and fallback behavior

Supported Mappings

Horizon Code HTTP Status
tx_bad_seq 409
tx_insufficient_fee 422
tx_bad_auth 403
op_no_trust 422
op_line_full 422
op_no_destination 404
op_underfunded 422
op_low_reserve 422
transaction_failed 422
not_found 404

Verification

PASS tests/errorHandler.test.js
PASS tests/horizonStatusMapper.test.js

Test Suites: 2 passed, 2 total
Tests: 11 passed, 11 total

The implementation preserves backward compatibility by falling back to the original Horizon response status when no mapped result code is available.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 2, 2026

@AlphaMaleBaDI Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Sulex45 Sulex45 merged commit 3d5830c into stellarkit-lab-devtools:main Jun 2, 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.

Horizon Error Code to HTTP Status Mapper

2 participants