Skip to main content

fauna_api/
error.rs

1use thiserror::Error as ThisError;
2
3/// Every fallible SDK call returns this. `Http` carries the response body the
4/// TypeScript SDK throws as `new Error(await response.text())`.
5#[derive(Debug, ThisError)]
6pub enum Error {
7    #[error("{body}")]
8    Http { status: u16, body: String },
9    #[error("{0}")]
10    Message(String),
11    #[error(transparent)]
12    Request(#[from] reqwest::Error),
13    #[error(transparent)]
14    Json(#[from] serde_json::Error),
15    #[error(transparent)]
16    WebSocket(#[from] Box<tokio_tungstenite::tungstenite::Error>),
17    /// A push to a dataset where no row was let through: why, and each row's reason.
18    #[error("{}", .0.message)]
19    PushRefused(crate::marmot::research::PushRefused),
20}
21
22impl From<tokio_tungstenite::tungstenite::Error> for Error {
23    fn from(error: tokio_tungstenite::tungstenite::Error) -> Self {
24        Error::WebSocket(Box::new(error))
25    }
26}
27
28pub type Result<T> = std::result::Result<T, Error>;