firebase_rs_sdk/app_check/
errors.rs

1use std::fmt;
2use std::time::SystemTimeError;
3
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum AppCheckError {
6    AlreadyInitialized { app_name: String },
7    UseBeforeActivation { app_name: String },
8    TokenFetchFailed { message: String },
9    InvalidConfiguration { message: String },
10    ProviderError { message: String },
11    TokenExpired,
12    Internal(String),
13}
14
15pub type AppCheckResult<T> = Result<T, AppCheckError>;
16
17impl fmt::Display for AppCheckError {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            AppCheckError::AlreadyInitialized { app_name } => write!(
21                f,
22                "App Check already initialized for Firebase app '{app_name}' with different options"
23            ),
24            AppCheckError::UseBeforeActivation { app_name } => write!(
25                f,
26                "App Check used before initialize_app_check() for Firebase app '{app_name}'"
27            ),
28            AppCheckError::TokenFetchFailed { message } => {
29                write!(f, "Failed to fetch App Check token: {message}")
30            }
31            AppCheckError::InvalidConfiguration { message } => {
32                write!(f, "Invalid App Check configuration: {message}")
33            }
34            AppCheckError::ProviderError { message } => {
35                write!(f, "App Check provider error: {message}")
36            }
37            AppCheckError::TokenExpired => {
38                write!(f, "App Check token has expired")
39            }
40            AppCheckError::Internal(message) => {
41                write!(f, "Internal App Check error: {message}")
42            }
43        }
44    }
45}
46
47impl std::error::Error for AppCheckError {}
48
49impl From<SystemTimeError> for AppCheckError {
50    fn from(error: SystemTimeError) -> Self {
51        AppCheckError::Internal(error.to_string())
52    }
53}