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
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
Description
src/errors.tsthrows plainErrorobjects with string messages. Consumers cannot reliablyswitchon error types — they must string-match the message, which breaks when wording changes. This issue adds a typedSdkErrorCodeenum and anSdkErrorclass that carries it.Acceptance Criteria
SdkErrorCodeenum exported fromsrc/errors.tswith at minimum:INVOICE_NOT_FOUND,INSUFFICIENT_FUNDS,DEADLINE_EXPIRED,INVALID_RECIPIENT,CONTRACT_REJECTED,NETWORK_TIMEOUT,RATE_LIMITEDSdkError extends Errorwithcode: SdkErrorCodeanddetails?: unknownfieldsthrow new Error(...)calls insrc/errors.tsreplaced withthrow new SdkError(...)isSdkError(e: unknown): e is SdkErrortype guard exportedSdkErrorandSdkErrorCodeexported fromsrc/index.tsisSdkErrorreturns true/false correctly,SdkErrorcarries correct code, existing string messages preserved in.messageContext
src/errors.tsandsrc/index.ts.messagestring content of any existing error — only add thecodefield