Skip to content

Add typed SdkErrorCode enum and SdkError class to errors.ts #607

Description

@Kingsman-99

Description

src/errors.ts throws plain Error objects with string messages. Consumers cannot reliably switch on error types — they must string-match the message, which breaks when wording changes. This issue adds a typed SdkErrorCode enum and an SdkError class that carries it.

Acceptance Criteria

  • SdkErrorCode enum exported from src/errors.ts with at minimum: INVOICE_NOT_FOUND, INSUFFICIENT_FUNDS, DEADLINE_EXPIRED, INVALID_RECIPIENT, CONTRACT_REJECTED, NETWORK_TIMEOUT, RATE_LIMITED
  • SdkError extends Error with code: SdkErrorCode and details?: unknown fields
  • All existing throw new Error(...) calls in src/errors.ts replaced with throw new SdkError(...)
  • isSdkError(e: unknown): e is SdkError type guard exported
  • SdkError and SdkErrorCode exported from src/index.ts
  • Unit tests: isSdkError returns true/false correctly, SdkError carries correct code, existing string messages preserved in .message

Context

  • Target file: src/errors.ts and src/index.ts
  • Do not change the .message string content of any existing error — only add the code field

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions