mz_frontegg_auth/
error.rs1use std::sync::Arc;
11use thiserror::Error;
12
13use crate::AppPasswordParseError;
14
15#[derive(Clone, Error, Debug)]
16pub enum Error {
17 #[error(transparent)]
18 InvalidPasswordFormat(#[from] AppPasswordParseError),
19 #[error("invalid token format: {0}")]
20 InvalidTokenFormat(#[from] jsonwebtoken::errors::Error),
21 #[error("authentication token exchange failed: {0}")]
22 ReqwestError(Arc<reqwest::Error>),
23 #[error("middleware programming error: {0}")]
24 MiddlewareError(Arc<anyhow::Error>),
25 #[error("authentication token missing claims")]
26 MissingClaims,
27 #[error("authentication token expired")]
28 TokenExpired,
29 #[error("unauthorized organization")]
30 UnauthorizedTenant,
31 #[error("the app password was not valid")]
32 InvalidAppPassword,
33 #[error("user in access token did not match the expected user")]
34 WrongUser,
35 #[error("user name too long")]
36 UserNameTooLong,
37 #[error("user declared by tenant access token cannot be an email address")]
38 InvalidTenantApiTokenUser,
39 #[error("request timeout")]
40 Timeout(Arc<tokio::time::error::Elapsed>),
41 #[error("internal error")]
42 Internal(Arc<anyhow::Error>),
43}
44
45impl From<anyhow::Error> for Error {
46 fn from(value: anyhow::Error) -> Self {
47 Error::Internal(Arc::new(value))
48 }
49}
50
51impl From<tokio::time::error::Elapsed> for Error {
52 fn from(value: tokio::time::error::Elapsed) -> Self {
53 Error::Timeout(Arc::new(value))
54 }
55}
56
57impl From<reqwest::Error> for Error {
58 fn from(value: reqwest::Error) -> Self {
59 Error::ReqwestError(Arc::new(value))
60 }
61}
62
63impl From<reqwest_middleware::Error> for Error {
64 fn from(value: reqwest_middleware::Error) -> Self {
65 match value {
66 reqwest_middleware::Error::Middleware(e) => Error::MiddlewareError(Arc::new(e)),
67 reqwest_middleware::Error::Reqwest(e) => Error::ReqwestError(Arc::new(e)),
68 }
69 }
70}