firebase_rs_sdk/auth/
error.rs

1use crate::app::AppError;
2use crate::util::FirebaseError;
3use std::fmt;
4
5pub type AuthResult<T> = Result<T, AuthError>;
6
7#[derive(Debug, Clone)]
8pub enum AuthError {
9    Firebase(FirebaseError),
10    App(AppError),
11    Network(String),
12    InvalidCredential(String),
13    NotImplemented(&'static str),
14}
15
16impl fmt::Display for AuthError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            AuthError::Firebase(err) => write!(f, "{err}"),
20            AuthError::App(err) => write!(f, "{err}"),
21            AuthError::Network(message) => write!(f, "Network error: {message}"),
22            AuthError::InvalidCredential(message) => write!(f, "Invalid credential: {message}"),
23            AuthError::NotImplemented(feature) => write!(f, "{feature} is not implemented"),
24        }
25    }
26}
27
28impl std::error::Error for AuthError {}
29
30impl From<FirebaseError> for AuthError {
31    fn from(error: FirebaseError) -> Self {
32        AuthError::Firebase(error)
33    }
34}
35
36impl From<AppError> for AuthError {
37    fn from(error: AppError) -> Self {
38        AuthError::App(error)
39    }
40}