Skip to content

feat: add typed SdkErrorCode enum and SdkError class (#607) - #632

Merged
Kingsman-99 merged 1 commit into
Stellar-split:mainfrom
rasputin2525:feat/607-sdk-error-code-enum
Aug 26, 2026
Merged

feat: add typed SdkErrorCode enum and SdkError class (#607)#632
Kingsman-99 merged 1 commit into
Stellar-split:mainfrom
rasputin2525:feat/607-sdk-error-code-enum

Conversation

@rasputin2525

Copy link
Copy Markdown
Contributor

Title:
feat: add typed SdkErrorCode enum and SdkError class (#607)

Body:

Summary

Closes #607.

src/errors.ts consumers previously had no reliable way to switch on error
type — they had to string-match .message, which breaks whenever the
wording changes. This adds a typed error code so callers can branch on
err.code instead.

  • Added SdkErrorCode enum to src/errors.ts with INVOICE_NOT_FOUND,
    INSUFFICIENT_FUNDS, DEADLINE_EXPIRED, INVALID_RECIPIENT,
  • Added SdkError class extending Error with code: SdkErrorCode and
    details?: unknown
  • Added isSdkError(e: unknown): e is SdkError type guard
  • Exported SdkError, SdkErrorCode, and isSdkError from src/index.ts

Note on the "replace throw new Error(...)" acceptance criterion:
src/errors.ts already threw only typed StellarSplitError subclasses
everywhere — there were no plain throw new Error(...) calls in the file to
migrate, so this criterion is satisfied with no changes needed there.

Test plan

  • Added test/sdkError.test.ts covering: isSdkError true/false cases,
    SdkError carries the correct code, existing behavior (message,
    details, instanceof Error) preserved
  • npx vitest run test/sdkError.test.ts test/errorSuggestions.test.ts test/horizonErrorClassifier.test.ts — all 50 tests pass
  • Verified no new TypeScript errors introduced (tsc --noEmit shows the
    same 217 pre-existing errors on main, none touching errors.ts or
    index.ts's new exports)

Consumers previously had to string-match error messages to distinguish
failure cases. Add an SdkErrorCode enum and SdkError class (extends
Error, carries code + optional details) so callers can switch on
err.code instead. Export both plus an isSdkError type guard from
src/index.ts.

Note: src/errors.ts already used typed StellarSplitError subclasses
throughout (no plain `throw new Error(...)` calls existed), so there
was nothing to migrate for that acceptance criterion.
@Kingsman-99
Kingsman-99 merged commit 8e7ce67 into Stellar-split:main Aug 26, 2026
2 checks passed
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 typed SdkErrorCode enum and SdkError class to errors.ts

2 participants