1use error_support::{ErrorHandling, GetErrorHandling};
6
7pub type Result<T> = std::result::Result<T, Error>;
8pub type ApiResult<T> = std::result::Result<T, ApiError>;
9
10#[derive(Debug, thiserror::Error, uniffi::Error)]
11pub enum ApiError {
12 #[error("Something unexpected occurred.")]
13 Other { reason: String },
14}
15
16#[derive(Debug, thiserror::Error)]
17pub enum Error {
18 #[error("Timestamp was invalid")]
19 InvalidTimestamp { timestamp: i64 },
20
21 #[error("URL parse error: {0}")]
22 UrlParseError(#[from] url::ParseError),
23
24 #[error("Viaduct error: {0}")]
25 ViaductError(#[from] viaduct::Error),
26
27 #[error("UniFFI callback error: {0}")]
28 UniFFICallbackError(#[from] uniffi::UnexpectedUniFFICallbackError),
29}
30
31impl GetErrorHandling for Error {
33 type ExternalError = ApiError;
34
35 fn get_error_handling(&self) -> ErrorHandling<Self::ExternalError> {
36 ErrorHandling::convert(ApiError::Other {
37 reason: self.to_string(),
38 })
39 }
40}