summaryrefslogtreecommitdiff
path: root/server/src/error.rs
blob: 439e81b95ac414ad57a75889872b737da442588f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use axum::{http::StatusCode, response::IntoResponse};
use openidconnect::{core::CoreErrorResponseType, StandardErrorResponse, ClaimsVerificationError};

type RequestTokenError = openidconnect::RequestTokenError<
    openidconnect::reqwest::Error<reqwest::Error>,
    StandardErrorResponse<CoreErrorResponseType>,
>;

#[derive(thiserror::Error, Debug)]
pub enum BridgeError {
    #[error("Invalid request: {0}")]
    InvalidRequest(String),

    #[error("Backend request failed")]
    Backend(#[from] RequestTokenError),

    #[error("Unexpected authorization error")]
    UnexpectedInvalidAuthorization(#[from] ClaimsVerificationError),
    
    #[error("Internal server error: {0}")]
    Internal(String),
}

impl IntoResponse for BridgeError {
    fn into_response(self) -> axum::response::Response {
        (StatusCode::INTERNAL_SERVER_ERROR, format!("Error: {self}")).into_response()
    }
}