Skip to main content

authkestra_core/
error.rs

1use serde::{Deserialize, Serialize};
2
3/// Errors that can occur during the authentication process.
4#[derive(Debug, thiserror::Error)]
5pub enum AuthError {
6    /// An error returned by the authentication provider
7    #[error("Provider error: {0}")]
8    Provider(String),
9    /// The provided credentials (email/password) are invalid
10    #[error("Invalid credentials")]
11    InvalidCredentials,
12    /// The authorization code is invalid or expired
13    #[error("Invalid code")]
14    InvalidCode,
15    /// A network error occurred during communication with the provider
16    #[error("Network error")]
17    Network,
18    /// An error occurred during session management
19    #[error("Session error: {0}")]
20    Session(String),
21    /// An error occurred during token processing
22    #[error("Token error: {0}")]
23    Token(String),
24    /// The CSRF state parameter does not match the expected value
25    #[error("CSRF state mismatch")]
26    CsrfMismatch,
27    /// An error occurred during OIDC discovery
28    #[error("Discovery error: {0}")]
29    Discovery(String),
30    /// A required component (e.g., SessionManager, TokenManager) is missing
31    #[error("Missing component: {0}")]
32    ComponentMissing(String),
33}
34
35/// Represents an error response from an OAuth2 provider.
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct OAuthErrorResponse {
38    /// The error code.
39    pub error: String,
40    /// A human-readable ASCII text description of the error.
41    pub error_description: Option<String>,
42}