From accb9032b9abe595020a27dd2f7b666cb7028f67 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Thu, 13 Oct 2022 08:12:59 -0400 Subject: Add AuthenticatedSession request extractor --- server/src/error.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/src/error.rs') diff --git a/server/src/error.rs b/server/src/error.rs index cea23e7..aef2687 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -1,4 +1,4 @@ -use axum::{http::StatusCode, response::IntoResponse}; +use axum::{http::{StatusCode, self}, response::IntoResponse}; use openidconnect::{core::CoreErrorResponseType, ClaimsVerificationError, StandardErrorResponse}; use tracing::error; @@ -26,6 +26,9 @@ pub enum BridgeError { #[error("Unexpected authorization error")] UnexpectedInvalidAuthorization(#[from] ClaimsVerificationError), + #[error("User is not logged in")] + NotLoggedIn, + #[error("Authentication error")] SigningFailed(#[from] openidconnect::SigningError), @@ -42,9 +45,15 @@ pub enum BridgeError { DurationOutOfRange(#[from] time::OutOfRangeError), } +impl BridgeError { + pub fn as_rejection(&self) -> (http::StatusCode, String) { + (StatusCode::INTERNAL_SERVER_ERROR, format!("Error: {self}")) + } +} + impl IntoResponse for BridgeError { fn into_response(self) -> axum::response::Response { error!("Error occurred: {self:?}"); - (StatusCode::INTERNAL_SERVER_ERROR, format!("Error: {self}")).into_response() + self.as_rejection().into_response() } } -- cgit v1.2.3