i18n+filtering fork - fluent-templates v2
at main 132 lines 5.7 kB view raw
1use thiserror::Error; 2 3/// Represents errors that can occur during OAuth model operations. 4/// 5/// These errors relate to OAuth authentication flows, session management, 6/// and cryptographic operations with JWT and JWK. 7#[derive(Debug, Error)] 8pub enum OAuthModelError { 9 /// Error when creating a DPoP secret from a JWK fails. 10 /// 11 /// This error occurs when attempting to convert a JSON Web Key (JWK) 12 /// into a secret key for DPoP (Demonstrating Proof-of-Possession) operations, 13 /// typically due to invalid key format or cryptographic errors. 14 #[error("error-oauth-model-1 Failed to create DPoP secret from JWK: {0:?}")] 15 DpopSecretFromJwkFailed(elliptic_curve::Error), 16 17 /// Error when the OAuth flow state is invalid. 18 /// 19 /// This error occurs when the state parameter in an OAuth flow 20 /// does not match the expected value or cannot be verified, 21 /// which could indicate a potential CSRF attack or session mismatch. 22 #[error("error-oauth-model-2 Invalid OAuth flow state")] 23 InvalidOAuthFlowState(), 24 25 /// Error when required OAuth session data is missing. 26 /// 27 /// This error occurs when attempting to use an OAuth session 28 /// that is missing critical data needed for authentication or 29 /// authorization operations, such as tokens or session identifiers. 30 #[error("error-oauth-model-3 Missing required OAuth session data")] 31 MissingRequiredOAuthSessionData(), 32 33 /// Error when an OAuth session has expired. 34 /// 35 /// This error occurs when attempting to use an OAuth session 36 /// that has exceeded its validity period and is no longer usable 37 /// for authentication or authorization purposes. 38 #[error("error-oauth-model-4 OAuth session has expired")] 39 OAuthSessionExpired(), 40} 41 42/// Represents errors that can occur during storage and database operations. 43#[derive(Debug, Error)] 44pub enum StorageError { 45 /// Error when a web session cannot be found in the database. 46 /// 47 /// This error occurs when attempting to retrieve a web session using an 48 /// invalid or expired session ID. 49 #[error("error-storage-1 Web session not found")] 50 WebSessionNotFound, 51 52 /// Error when a handle cannot be found in the database. 53 /// 54 /// This error occurs when attempting to retrieve a user handle that 55 /// doesn't exist in the system. 56 #[error("error-storage-2 Handle not found")] 57 HandleNotFound, 58 59 /// Error when a database record cannot be found. 60 /// 61 /// This error occurs when attempting to retrieve a specific record 62 /// using an ID or other identifier that doesn't exist in the database. 63 #[error("error-storage-3 Record not found: {0} {1:?}")] 64 RowNotFound(String, sqlx::Error), 65 66 /// Error when a database transaction cannot be committed. 67 /// 68 /// This error occurs when there is an issue finalizing a database 69 /// transaction, potentially causing data inconsistency. 70 #[error("error-storage-4 Cannot commit database transaction: {0:?}")] 71 CannotCommitDatabaseTransaction(sqlx::Error), 72 73 /// Error when a database transaction cannot be started. 74 /// 75 /// This error occurs when there is an issue initiating a database 76 /// transaction, typically due to connection issues or database constraints. 77 #[error("error-storage-5 Cannot begin database transaction: {0:?}")] 78 CannotBeginDatabaseTransaction(sqlx::Error), 79 80 /// Error when a database query cannot be executed. 81 /// 82 /// This error occurs when a SQL query fails to execute, typically due to 83 /// syntax errors, constraint violations, or database connectivity issues. 84 #[error("error-storage-6 Unable to execute query: {0:?}")] 85 UnableToExecuteQuery(sqlx::Error), 86 87 /// Error when an OAuth request cannot be found. 88 /// 89 /// This error occurs when attempting to retrieve an OAuth request 90 /// that doesn't exist or has expired. 91 #[error("error-storage-7 OAuth request not found")] 92 OAuthRequestNotFound, 93 94 /// Error when an RSVP cannot be found. 95 /// 96 /// This error occurs when attempting to retrieve an RSVP record 97 /// that doesn't exist in the database. 98 #[error("error-storage-8 RSVP not found")] 99 RSVPNotFound, 100 101 /// Error when an OAuth model operation fails. 102 /// 103 /// This error occurs when there's an issue with OAuth model operations, 104 /// such as token generation, validation, or storage. 105 #[error("error-storage-9 OAuth model error: {0}")] 106 OAuthModelError(#[from] OAuthModelError), 107} 108 109/// Represents errors that can occur during cache operations. 110#[derive(Debug, Error)] 111pub enum CacheError { 112 /// Error when a cache pool cannot be created. 113 /// 114 /// This error occurs when the system fails to initialize the Redis 115 /// connection pool, typically due to configuration or connectivity issues. 116 #[error("error-cache-1 Failed to create cache pool: {0:?}")] 117 FailedToCreatePool(deadpool_redis::CreatePoolError), 118 119 /// Error when a cache connection cannot be obtained. 120 /// 121 /// This error occurs when the system fails to get a connection from 122 /// the Redis connection pool, typically due to pool exhaustion or connectivity issues. 123 #[error("error-cache-2 Failed to get connection: {0:?}")] 124 FailedToGetConnection(deadpool_redis::PoolError), 125 126 /// Error when a session cannot be placed in the refresh queue. 127 /// 128 /// This error occurs when the system fails to add a session to the 129 /// Redis-backed refresh queue, typically due to Redis errors or connectivity issues. 130 #[error("error-cache-3 Failed to place session group into refresh queue: {0:?}")] 131 FailedToPlaceInRefreshQueue(deadpool_redis::redis::RedisError), 132}