31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1 | use std::sync::Arc; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 2 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 3 | use matrix_sdk::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 4 | HttpError, RefreshTokenError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 5 | authentication::oauth::error::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 6 | OAuthAuthorizationCodeError, OAuthDiscoveryError, OAuthError, OAuthTokenRevocationError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 7 | RequestTokenError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 8 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | encryption::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 10 | identities::{ManualVerifyError, RequestVerificationError}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 11 | recovery::RecoveryError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 12 | secret_storage::{ImportError, SecretStorageError}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 13 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 14 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 15 | #[cfg(feature = "serde")] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 16 | use serde::{Deserialize, Serialize}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 17 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 18 | use crate::InteractiveAuthChallenge; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 19 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 20 | /// the one thing that goes wrong, for commands and queries alike. match on `kind`, show `message` |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 21 | #[derive(Clone, Debug, thiserror::Error)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 22 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 23 | #[error("{message}")] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 24 | #[non_exhaustive] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 25 | pub struct Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 26 | pub kind: ErrorKind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 27 | pub message: String, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 28 | /// set when the server wants interactive auth before it'll do the thing |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 29 | pub challenge: Option<Box<InteractiveAuthChallenge>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 30 | #[source] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 31 | #[cfg_attr(feature = "serde", serde(skip))] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 32 | source: Option<Arc<dyn std::error::Error + Send + Sync>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 33 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 34 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 35 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 36 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 37 | #[non_exhaustive] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 38 | pub enum ErrorKind { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 39 | /// the engine stopped, or the task doing the work died, before answering |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 40 | Interrupted, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 41 | Unauthenticated, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 42 | InteractiveAuthRequired, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 43 | Invalid, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 44 | RoomUnknown, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 45 | RoomNotOpen, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 46 | TimelineNotOpen, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 47 | RoomBusy, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 48 | QueueFull, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 49 | EmptyBody, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 50 | MediaUnknown, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 51 | MediaTooLarge, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 52 | MediaUnavailable, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 53 | VerificationInactive, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 54 | VerificationUnsupported, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 55 | NoCrossSigningIdentity, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 56 | RecoveryRejected, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 57 | Network, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 58 | Server, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 59 | Store, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 60 | Timeline, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 61 | Encryption, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 62 | Other, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 63 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 64 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 65 | impl Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 66 | pub(crate) fn new(kind: ErrorKind, message: impl Into<String>) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 67 | Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 68 | kind, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 69 | message: message.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 70 | challenge: None, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 71 | source: None, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 72 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 73 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 74 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 75 | pub(crate) fn with_source( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 76 | kind: ErrorKind, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 77 | message: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 78 | source: impl std::error::Error + Send + Sync + 'static, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 79 | ) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 80 | Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 81 | source: Some(Arc::new(source)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 82 | ..Self::new(kind, message) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 83 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 84 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 85 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 86 | pub(crate) fn interrupted() -> Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 87 | Self::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 88 | ErrorKind::Interrupted, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 89 | "the engine stopped before the operation finished", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 90 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 91 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 92 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 93 | pub(crate) fn room_unknown() -> Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 94 | Self::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 95 | ErrorKind::RoomUnknown, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 96 | "room is not available in the local store", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 97 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 98 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 99 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 100 | pub(crate) fn interactive_auth(challenge: InteractiveAuthChallenge) -> Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 101 | Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 102 | challenge: Some(Box::new(challenge)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 103 | ..Self::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 104 | ErrorKind::InteractiveAuthRequired, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 105 | "interactive authentication is required", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 106 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 107 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 108 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 109 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 110 | pub(crate) fn from_sdk(message: impl Into<String>, source: matrix_sdk::Error) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 111 | Self::with_source(classify_sdk_error(&source), message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 112 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 113 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 114 | pub(crate) fn from_http(message: impl Into<String>, source: HttpError) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 115 | Self::with_source(classify_http_error(&source), message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 116 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 117 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 118 | pub(crate) fn from_refresh_token( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 119 | message: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 120 | source: RefreshTokenError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 121 | ) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 122 | Self::with_source(classify_refresh_token_error(&source), message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 123 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 124 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 125 | pub(crate) fn from_recovery(message: impl Into<String>, source: RecoveryError) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 126 | let kind = match &source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 127 | RecoveryError::Sdk(source) => classify_sdk_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 128 | RecoveryError::SecretStorage(SecretStorageError::Sdk(source)) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 129 | classify_sdk_error(source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 130 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 131 | RecoveryError::SecretStorage(SecretStorageError::ImportError { error, .. }) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 132 | match error { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 133 | ImportError::Sdk(source) => classify_sdk_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 134 | _ => ErrorKind::RecoveryRejected, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 135 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 136 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 137 | RecoveryError::SecretStorage(SecretStorageError::Verification(source)) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 138 | match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 139 | ManualVerifyError::Http(source) => classify_http_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 140 | _ => ErrorKind::RecoveryRejected, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 141 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 142 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 143 | RecoveryError::SecretStorage(SecretStorageError::SecretStorageKey(_)) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 144 | ErrorKind::RecoveryRejected |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 145 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 146 | RecoveryError::SecretStorage(SecretStorageError::Storage(_)) => ErrorKind::Store, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 147 | RecoveryError::BackupExistsOnServer | RecoveryError::SecretStorage(_) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 148 | ErrorKind::RecoveryRejected |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 149 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 150 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 151 | Self::with_source(kind, message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 152 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 153 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 154 | pub(crate) fn from_verification_request( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 155 | message: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 156 | source: RequestVerificationError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 157 | ) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 158 | let kind = match &source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 159 | RequestVerificationError::Sdk(source) => classify_sdk_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 160 | RequestVerificationError::RoomCreation(_) => ErrorKind::Encryption, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 161 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 162 | Self::with_source(kind, message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 163 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 164 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 165 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 166 | impl PartialEq for Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 167 | fn eq(&self, other: &Self) -> bool { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 168 | self.kind == other.kind |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 169 | && self.message == other.message |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 170 | && self.challenge == other.challenge |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 171 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 172 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 173 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 174 | pub(crate) fn classify_sdk_error(source: &matrix_sdk::Error) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 175 | match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 176 | matrix_sdk::Error::Http(source) => classify_http_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 177 | matrix_sdk::Error::OAuth(source) => classify_oauth_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 178 | matrix_sdk::Error::AuthenticationRequired => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 179 | matrix_sdk::Error::BadCryptoStoreState |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 180 | | matrix_sdk::Error::CryptoStoreError(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 181 | | matrix_sdk::Error::CrossProcessLockError(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 182 | | matrix_sdk::Error::StateStore(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 183 | | matrix_sdk::Error::EventCacheStore(_) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 184 | | matrix_sdk::Error::MediaStore(_) => ErrorKind::Store, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 185 | matrix_sdk::Error::NoOlmMachine |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 186 | | matrix_sdk::Error::OlmError(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 187 | | matrix_sdk::Error::MegolmError(_) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 188 | | matrix_sdk::Error::DecryptorError(_) => ErrorKind::Encryption, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 189 | matrix_sdk::Error::Media(_) => ErrorKind::MediaUnavailable, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 190 | matrix_sdk::Error::Timeout => ErrorKind::Network, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 191 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 192 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 193 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 194 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 195 | fn classify_http_error(source: &HttpError) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 196 | match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 197 | HttpError::Reqwest(_) => ErrorKind::Network, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 198 | HttpError::Api(_) => ErrorKind::Server, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 199 | HttpError::RefreshToken(source) => classify_refresh_token_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 200 | HttpError::Cached(source) => classify_http_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 201 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 202 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 203 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 204 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 205 | fn classify_refresh_token_error(source: &RefreshTokenError) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 206 | match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 207 | RefreshTokenError::RefreshTokenRequired => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 208 | RefreshTokenError::MatrixAuth(source) => classify_http_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 209 | RefreshTokenError::OAuth(source) => classify_oauth_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 210 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 211 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 212 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 213 | fn classify_oauth_error(source: &OAuthError) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 214 | let classify_token_request_error = |source: &_| match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 215 | RequestTokenError::Request(_) => ErrorKind::Network, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 216 | RequestTokenError::ServerResponse(_) => ErrorKind::Unauthenticated, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 217 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 218 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 219 | match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 220 | OAuthError::Discovery(source) => match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 221 | OAuthDiscoveryError::Http(source) => classify_http_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 222 | OAuthDiscoveryError::Oidc(source) => classify_token_request_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 223 | _ => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 224 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 225 | OAuthError::RefreshToken(source) => classify_token_request_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 226 | OAuthError::AuthorizationCode(OAuthAuthorizationCodeError::RequestToken(source)) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 227 | classify_token_request_error(source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 228 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 229 | OAuthError::AuthorizationCode(_) => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 230 | OAuthError::Logout(source) => match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 231 | OAuthTokenRevocationError::Revoke(RequestTokenError::Request(_)) => ErrorKind::Network, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 232 | OAuthTokenRevocationError::Revoke(RequestTokenError::ServerResponse(_)) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 233 | ErrorKind::Unauthenticated |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 234 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 235 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 236 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 237 | _ => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 238 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 239 | } |