1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
45use error_support::{ErrorHandling, GetErrorHandling};
67pub type Result<T> = std::result::Result<T, Error>;
8pub type ApiResult<T> = std::result::Result<T, ApiError>;
910#[derive(Debug, thiserror::Error, uniffi::Error)]
11pub enum ApiError {
12#[error("Something unexpected occurred.")]
13Other { reason: String },
14}
1516#[derive(Debug, thiserror::Error)]
17pub enum Error {
18#[error("Timestamp was invalid")]
19InvalidTimestamp { timestamp: i64 },
2021#[error("URL parse error: {0}")]
22UrlParseError(#[from] url::ParseError),
2324#[error("Viaduct error: {0}")]
25ViaductError(#[from] viaduct::Error),
2627#[error("UniFFI callback error: {0}")]
28UniFFICallbackError(#[from] uniffi::UnexpectedUniFFICallbackError),
29}
3031// Define how our internal errors are handled and converted to external errors.
32impl GetErrorHandling for Error {
33type ExternalError = ApiError;
3435fn get_error_handling(&self) -> ErrorHandling<Self::ExternalError> {
36 ErrorHandling::convert(ApiError::Other {
37 reason: self.to_string(),
38 })
39 }
40}