use thiserror::Error;
#[derive(Clone, Debug, Eq, Error, PartialEq)]
pub enum StdbAuthCommandError {
#[error("another authentication operation is already pending")]
PendingOperation,
#[error("no authentication session is active")]
NoSession,
#[error("no authentication operation is pending")]
NoPendingOperation,
#[error("the active authentication session cannot be refreshed")]
MissingRefreshToken,
#[error("the active authentication session does not include a client ID")]
MissingClientId,
#[error("unsupported authentication command: {0}")]
Unsupported(String),
}
#[derive(Debug, Error)]
pub enum StdbAuthError {
#[error("auth command rejected: {0}")]
Command(#[from] StdbAuthCommandError),
#[error("auth HTTP request failed: {0}")]
Http(#[from] reqwest::Error),
#[error("auth response decode failed: {0}")]
Decode(#[from] serde_json::Error),
#[error("auth operation timed out")]
Timeout,
#[error("invalid auth configuration: {0}")]
InvalidConfig(String),
#[error("invalid token response: {0}")]
InvalidTokenResponse(String),
#[error("invalid OIDC callback: {0}")]
InvalidOidcCallback(String),
#[error("auth provider error: {0}")]
Provider(String),
#[error("unsupported auth operation: {0}")]
Unsupported(String),
#[error("auth operation failed: {0}")]
Internal(String),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn command_error_converts_to_auth_error() {
let error = StdbAuthError::from(StdbAuthCommandError::NoSession);
assert!(matches!(
error,
StdbAuthError::Command(StdbAuthCommandError::NoSession)
));
}
}