error.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //! Error types for the NpubCash SDK
  2. use thiserror::Error;
  3. /// Result type for NpubCash SDK operations
  4. pub type Result<T> = std::result::Result<T, Error>;
  5. /// Error types that can occur when using the NpubCash SDK
  6. #[derive(Debug, Error)]
  7. pub enum Error {
  8. /// API returned an error response
  9. #[error("API error ({status}): {message}")]
  10. Api {
  11. /// Error message from the API
  12. message: String,
  13. /// HTTP status code
  14. status: u16,
  15. },
  16. /// Authentication failed
  17. #[error("Authentication failed: {0}")]
  18. Auth(String),
  19. /// HTTP request failed
  20. #[error("HTTP request failed: {0}")]
  21. Http(#[from] cdk_common::HttpError),
  22. /// JSON serialization/deserialization error
  23. #[error("JSON serialization error: {0}")]
  24. Serde(#[from] serde_json::Error),
  25. /// Invalid URL
  26. #[error("Invalid URL: {0}")]
  27. Url(#[from] url::ParseError),
  28. /// Nostr signing error
  29. #[error("Nostr signing error: {0}")]
  30. Nostr(String),
  31. /// Custom error message
  32. #[error("{0}")]
  33. Custom(String),
  34. }