Error Handling
The TypeScript SDK currently exposes three error classes:
Sw4pAuthErrorSw4pRateLimitErrorSw4pApiError
TypeScript Example
typescript
import {
Sw4pApiError,
Sw4pAuthError,
Sw4pRateLimitError,
} from "@sw4p/sdk";
try {
await client.transfer(params);
} catch (error) {
if (error instanceof Sw4pAuthError) {
console.error("Authentication failed:", error.code);
throw error;
}
if (error instanceof Sw4pRateLimitError) {
console.error("Retry after:", error.retryAfter);
throw error;
}
if (error instanceof Sw4pApiError) {
console.error(`API ${error.status}: ${error.code} - ${error.message}`);
throw error;
}
throw error;
}
Rust Example
rust
use sw4p_sdk::Sw4pError;
match client.estimate(¶ms).await {
Ok(result) => println!("fee: {}", result.fee.total),
Err(Sw4pError::Auth(body)) => eprintln!("auth failed: {}", body.message),
Err(Sw4pError::RateLimit { body, retry_after_ms }) => {
eprintln!("rate limited: {} {:?}", body.message, retry_after_ms);
}
Err(Sw4pError::Api { status, body }) => {
eprintln!("api error {}: {}", status, body.message);
}
Err(other) => eprintln!("error: {}", other),
}
Notes
- Rate limiting surfaces
Retry-Afteras milliseconds on the TypeScript side. - The SDK does not currently expose separate transfer-not-found or network-only error classes.
- Helper status failures are reported through
status()/getIntentStatus()as route state, not only through thrown request errors.