Add automated error mapping for custom Astroid API error codes - #205
Open
charlesejemai-cyber wants to merge 2 commits into
Open
Add automated error mapping for custom Astroid API error codes#205charlesejemai-cyber wants to merge 2 commits into
charlesejemai-cyber wants to merge 2 commits into
Conversation
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
|
@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! 🚀 |
Contributor
|
Please resolve conflict @charlesejemai-cyber |
Contributor
Author
|
@K1NGD4VID please review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 oninstanceofand handle failures gracefully.Changes
packages/client/src/errors.tsStellarHorizonErrorclass carryingstellarCode/operationCode.parseErrorBody(status, body, requestId?)andparseErrorResponse(response)that synchronously/asynchronously translate error payloads into typed errors.detectStellarCode()extracts Horizonresult_codesfrom various payload shapes.errors[]/validationErrors[]/details.fields).packages/client/src/index.tsparseErrorBody,parseErrorResponse,StellarHorizonError,createErrorParserMiddleware, and the typed error classes from the package entry.packages/client/src/errors.test.tsPromiseinstead of parsed JSON, so error payloads are actually parsed and verified.packages/core/src/config.ts(build/CI fix)resolveConfigreferenced an undefinedfetchImpl(runtime crash on every client construction); now usesconfig.fetch ?? globalThis.fetch.AuthConfig; addedrefreshToken/onTokenUpdateto config.packages/types/src/common.ts&src/analytics.ts(build/CI fix)ApiErrorCode/ApiError(duplicate re-declarations broke the@astroid/typesbuild).PaginationParamstype.PaginatedResponsealias; addedAnalyticsQueryandTimeSeriesMetricPointtypes that were referenced but undefined (broke DTS build).Acceptance
@astroid/clienttranslates error codes to specific SDK errorsTest status
@astroid/typesbuilds cleanly and its 51 tests pass. The pure error-mapping unit tests pass:errors.test.ts— 3/3error-parser-middleware.test.ts— 25/27__tests__/error.test.ts— 19/24The 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.tsimportsAuthService/WalletServicewhich the resource packages export asAuthResource/WalletResource). Fully repairing that rewrite is tracked separately and intentionally out of scope for this error-mapping PR.