dune_api/
error.rs

1//! Error types for the Dune API client
2//!
3//! This module provides the error types for the Dune API client,
4//! built on top of the shared `ApiError` infrastructure.
5
6use thiserror::Error;
7pub use yldfi_common::api::ApiError;
8
9/// Domain-specific errors for Dune API
10#[derive(Error, Debug)]
11pub enum DomainError {
12    /// Invalid API key
13    #[error("Invalid API key")]
14    InvalidApiKey,
15
16    /// Query execution failed
17    #[error("Query execution failed: {0}")]
18    ExecutionFailed(String),
19
20    /// Query execution timed out
21    #[error("Query execution timed out after {0} seconds")]
22    ExecutionTimeout(u64),
23
24    /// Insufficient credits
25    #[error("Insufficient credits")]
26    InsufficientCredits,
27
28    /// Resource not found
29    #[error("Resource not found: {0}")]
30    NotFound(String),
31}
32
33/// Error type for Dune API operations
34pub type Error = ApiError<DomainError>;
35
36/// Result type for Dune API operations
37pub type Result<T> = std::result::Result<T, Error>;
38
39// Convenience constructors for domain errors
40/// Create an invalid API key error
41pub fn invalid_api_key() -> Error {
42    ApiError::domain(DomainError::InvalidApiKey)
43}
44
45/// Create an execution failed error
46pub fn execution_failed(message: impl Into<String>) -> Error {
47    ApiError::domain(DomainError::ExecutionFailed(message.into()))
48}
49
50/// Create an execution timeout error
51pub fn execution_timeout(seconds: u64) -> Error {
52    ApiError::domain(DomainError::ExecutionTimeout(seconds))
53}
54
55/// Create an insufficient credits error
56pub fn insufficient_credits() -> Error {
57    ApiError::domain(DomainError::InsufficientCredits)
58}
59
60/// Create a not found error
61pub fn not_found(resource: impl Into<String>) -> Error {
62    ApiError::domain(DomainError::NotFound(resource.into()))
63}