Skip to content

Add automated error mapping for custom Astroid API error codes - #205

Open
charlesejemai-cyber wants to merge 2 commits into
ASTROIDX556:mainfrom
charlesejemai-cyber:110work
Open

Add automated error mapping for custom Astroid API error codes#205
charlesejemai-cyber wants to merge 2 commits into
ASTROIDX556:mainfrom
charlesejemai-cyber:110work

Conversation

@charlesejemai-cyber

Copy link
Copy Markdown
Contributor

Closes #110

Summary

Adds robust, strongly-typed error mapping across client responses in @astroid/client. Instead of surfacing generic HTTP errors, the SDK now translates raw error payloads into specific SDK error classes (BudgetExceededError, PolicyViolationError, InsufficientFundsError, ValidationError, StellarHorizonError, …) so agent code can branch on instanceof and handle failures gracefully.

Changes

packages/client/src/errors.ts

  • New StellarHorizonError class carrying stellarCode / operationCode.
  • New pure functions parseErrorBody(status, body, requestId?) and parseErrorResponse(response) that synchronously/asynchronously translate error payloads into typed errors.
  • detectStellarCode() extracts Horizon result_codes from various payload shapes.
  • Field-level validation extraction (errors[] / validationErrors[] / details.fields).
  • Re-exports all SDK domain error classes so downstream consumers get one import surface.

packages/client/src/index.ts

  • Exports parseErrorBody, parseErrorResponse, StellarHorizonError, createErrorParserMiddleware, and the typed error classes from the package entry.

packages/client/src/errors.test.ts

  • Fixes tests that passed an un-awaited Promise instead of parsed JSON, so error payloads are actually parsed and verified.

packages/core/src/config.ts (build/CI fix)

  • resolveConfig referenced an undefined fetchImpl (runtime crash on every client construction); now uses config.fetch ?? globalThis.fetch.
  • Removed duplicate keys / duplicate AuthConfig; added refreshToken / onTokenUpdate to config.

packages/types/src/common.ts & src/analytics.ts (build/CI fix)

  • Deduplicated ApiErrorCode / ApiError (duplicate re-declarations broke the @astroid/types build).
  • Added the missing PaginationParams type.
  • Removed the duplicate PaginatedResponse alias; added AnalyticsQuery and TimeSeriesMetricPoint types that were referenced but undefined (broke DTS build).

Acceptance

  • Custom error classes defined and exported across workspace packages
  • Response mapping in @astroid/client translates error codes to specific SDK errors
  • Unit tests verify correct error instantiation for various API error responses

Test status

@astroid/types builds cleanly and its 51 tests pass. The pure error-mapping unit tests pass:

  • errors.test.ts — 3/3
  • error-parser-middleware.test.ts — 25/27
  • __tests__/error.test.ts — 19/24

The 7 remaining failures are new Astroid(...) integration tests whose constructor path depends on the pre-existing, documented broken state of @astroid/core / the client resource import rewrite (e.g. index.ts imports AuthService/WalletService which the resource packages export as AuthResource/WalletResource). Fully repairing that rewrite is tracked separately and intentionally out of scope for this error-mapping PR.

Add strongly-typed error translation across @astroid/client responses so
developers can branch on specific error classes (BudgetExceededError,
PolicyViolationError, ...) instead of generic HTTP errors.

- client/src/errors.ts: add StellarHorizonError + parseErrorBody /
  parseErrorResponse/detectStellarCode; re-export all SDK error classes.
- client/src/index.ts: export new error helpers and domain error classes.
- client/src/errors.test.ts: fix tests passing an un-awaited Promise so
  error payloads are actually parsed.
- core/src/config.ts: fix resolveConfig referencing undefined fetchImpl,
  duplicate keys/interfaces; add refreshToken/onTokenUpdate config.
- types/src/common.ts: deduplicate ApiErrorCode/ApiError; add PaginationParams.
- types/src/analytics.ts: deduplicate PaginatedResponse; add AnalyticsQuery
  and TimeSeriesMetricPoint.

Closes ASTROIDX556#110
@drips-wave

drips-wave Bot commented Sep 2, 2026

Copy link
Copy Markdown

@charlesejemai-cyber 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

@K1NGD4VID

Copy link
Copy Markdown
Contributor

Please resolve conflict @charlesejemai-cyber

@charlesejemai-cyber

Copy link
Copy Markdown
Contributor Author

@K1NGD4VID please review

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.

Add automated error mapping for custom Astroid API error codes

2 participants