1#[derive(Debug)]
5pub enum Error {
6 BadRequest,
8 AuthenticationFailed(AuthenticationFailedError),
10 InternalError,
12 BadGateway(reqwest::Error),
14}
15
16impl From<AuthenticationFailedError> for Error {
17 fn from(err: AuthenticationFailedError) -> Self {
18 Self::AuthenticationFailed(err)
19 }
20}
21
22impl From<reqwest::Error> for Error {
23 fn from(err: reqwest::Error) -> Self {
24 Self::BadGateway(err)
25 }
26}
27
28impl From<Error> for http::StatusCode {
29 fn from(e: Error) -> Self {
31 use Error::*;
32 match e {
33 BadRequest => http::StatusCode::BAD_REQUEST,
34 AuthenticationFailed(_) => http::StatusCode::UNAUTHORIZED,
35 InternalError => http::StatusCode::INTERNAL_SERVER_ERROR,
36 BadGateway(_) => http::StatusCode::BAD_GATEWAY,
37 }
38 }
39}
40
41#[derive(Debug)]
43pub enum AuthenticationFailedError {
44 ClaimValidationError,
46 JwsDecodeError,
47}
48
49impl From<base64::DecodeError> for AuthenticationFailedError {
50 fn from(err: base64::DecodeError) -> Self {
52 log::warn!("Invalid ID token: {:?}", err);
53 Self::JwsDecodeError
54 }
55}
56
57impl From<serde_json::Error> for AuthenticationFailedError {
58 fn from(err: serde_json::Error) -> Self {
60 log::warn!("Invalid ID token: {:?}", err);
61 Self::JwsDecodeError
62 }
63}