1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910use std::sync::Arc;
11use thiserror::Error;
1213use crate::AppPasswordParseError;
1415#[derive(Clone, Error, Debug)]
16pub enum Error {
17#[error(transparent)]
18InvalidPasswordFormat(#[from] AppPasswordParseError),
19#[error("invalid token format: {0}")]
20InvalidTokenFormat(#[from] jsonwebtoken::errors::Error),
21#[error("authentication token exchange failed: {0}")]
22ReqwestError(Arc<reqwest::Error>),
23#[error("middleware programming error: {0}")]
24MiddlewareError(Arc<anyhow::Error>),
25#[error("authentication token missing claims")]
26MissingClaims,
27#[error("authentication token expired")]
28TokenExpired,
29#[error("unauthorized organization")]
30UnauthorizedTenant,
31#[error("the app password was not valid")]
32InvalidAppPassword,
33#[error("user in access token did not match the expected user")]
34WrongUser,
35#[error("user name too long")]
36UserNameTooLong,
37#[error("user declared by tenant access token cannot be an email address")]
38InvalidTenantApiTokenUser,
39#[error("request timeout")]
40Timeout(Arc<tokio::time::error::Elapsed>),
41#[error("internal error")]
42Internal(Arc<anyhow::Error>),
43}
4445impl From<anyhow::Error> for Error {
46fn from(value: anyhow::Error) -> Self {
47 Error::Internal(Arc::new(value))
48 }
49}
5051impl From<tokio::time::error::Elapsed> for Error {
52fn from(value: tokio::time::error::Elapsed) -> Self {
53 Error::Timeout(Arc::new(value))
54 }
55}
5657impl From<reqwest::Error> for Error {
58fn from(value: reqwest::Error) -> Self {
59 Error::ReqwestError(Arc::new(value))
60 }
61}
6263impl From<reqwest_middleware::Error> for Error {
64fn from(value: reqwest_middleware::Error) -> Self {
65match 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}