#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid base URL: {0}")]
InvalidBaseUrl(String),
#[error("missing environment variable: {0}")]
MissingEnvVar(&'static str),
#[error("read API request failed: {0}")]
Rpc(#[from] connectrpc::ConnectError),
#[cfg(feature = "cloud-auth")]
#[error("cloud auth setup failed: {0}")]
CloudAuth(#[from] olai_http::Error),
}
impl Error {
pub fn code(&self) -> Option<connectrpc::ErrorCode> {
match self {
Error::Rpc(e) => Some(e.code),
_ => None,
}
}
pub fn is_not_found(&self) -> bool {
self.code() == Some(connectrpc::ErrorCode::NotFound)
}
}