Implements comprehensive SDK support for three core services across four programming languages (JavaScript/TypeScript, Python, Go, Rust). ## New SDKs ### Wallet SDK - Key management (create, import, export) - Transaction signing - Message signing and verification - Balance and UTXO queries - Stealth address support ### RPC SDK - Block and transaction queries - Chain state information - Fee estimation - Mempool information - WebSocket subscriptions for real-time updates ### Storage SDK - Content upload and download - Pinning operations - CAR file support - Directory management - Gateway URL generation ## Shared Infrastructure - JSON Schema definitions for all 11 services - Common type definitions (Address, Amount, UTXO, etc.) - Unified error handling patterns - Builder patterns for configuration ## Package Updates - JavaScript: Updated to @synor/sdk with module exports - Python: Updated to synor-sdk with websockets dependency - Go: Added gorilla/websocket dependency - Rust: Added base64, urlencoding, multipart support ## Fixes - Fixed Tensor Default trait implementation - Fixed ProcessorType enum casing
74 lines
2.1 KiB
Rust
74 lines
2.1 KiB
Rust
//! Synor Storage SDK Error Types.
|
|
|
|
use std::fmt;
|
|
|
|
/// Storage SDK error type.
|
|
#[derive(Debug)]
|
|
pub enum StorageError {
|
|
/// HTTP request failed.
|
|
Request(String),
|
|
/// API returned an error.
|
|
Api {
|
|
message: String,
|
|
status_code: u16,
|
|
code: Option<String>,
|
|
},
|
|
/// JSON serialization/deserialization failed.
|
|
Serialization(String),
|
|
/// Invalid input provided.
|
|
Validation(String),
|
|
/// Request timed out.
|
|
Timeout,
|
|
/// IO error.
|
|
Io(String),
|
|
}
|
|
|
|
impl fmt::Display for StorageError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
StorageError::Request(msg) => write!(f, "Request error: {}", msg),
|
|
StorageError::Api {
|
|
message,
|
|
status_code,
|
|
code,
|
|
} => {
|
|
if let Some(c) = code {
|
|
write!(f, "API error [{}]: {} (status {})", c, message, status_code)
|
|
} else {
|
|
write!(f, "API error: {} (status {})", message, status_code)
|
|
}
|
|
}
|
|
StorageError::Serialization(msg) => write!(f, "Serialization error: {}", msg),
|
|
StorageError::Validation(msg) => write!(f, "Validation error: {}", msg),
|
|
StorageError::Timeout => write!(f, "Request timed out"),
|
|
StorageError::Io(msg) => write!(f, "IO error: {}", msg),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for StorageError {}
|
|
|
|
impl From<reqwest::Error> for StorageError {
|
|
fn from(err: reqwest::Error) -> Self {
|
|
if err.is_timeout() {
|
|
StorageError::Timeout
|
|
} else {
|
|
StorageError::Request(err.to_string())
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<serde_json::Error> for StorageError {
|
|
fn from(err: serde_json::Error) -> Self {
|
|
StorageError::Serialization(err.to_string())
|
|
}
|
|
}
|
|
|
|
impl From<std::io::Error> for StorageError {
|
|
fn from(err: std::io::Error) -> Self {
|
|
StorageError::Io(err.to_string())
|
|
}
|
|
}
|
|
|
|
/// Result type alias for Storage operations.
|
|
pub type Result<T> = std::result::Result<T, StorageError>;
|