Skip to content

Commit 89a85a2

Browse files
committed
Human-readable error page on the authorization endpoint
1 parent 9b99057 commit 89a85a2

File tree

1 file changed

+9
-23
lines changed
  • crates/handlers/src/oauth2/authorization

1 file changed

+9
-23
lines changed

crates/handlers/src/oauth2/authorization/mod.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use axum::{
99
response::{IntoResponse, Response},
1010
};
1111
use hyper::StatusCode;
12-
use mas_axum_utils::{SessionInfoExt, cookies::CookieJar, record_error};
12+
use mas_axum_utils::{GenericError, InternalError, SessionInfoExt, cookies::CookieJar};
1313
use mas_data_model::{AuthorizationCode, Pkce};
1414
use mas_router::{PostAuthAction, UrlBuilder};
1515
use mas_storage::{
@@ -53,29 +53,15 @@ pub enum RouteError {
5353

5454
impl IntoResponse for RouteError {
5555
fn into_response(self) -> axum::response::Response {
56-
let sentry_event_id = record_error!(self, Self::Internal(_));
57-
// TODO: better error pages
58-
let response = match self {
59-
RouteError::Internal(e) => {
60-
(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response()
56+
match self {
57+
Self::Internal(e) => InternalError::new(e).into_response(),
58+
e @ (Self::ClientNotFound
59+
| Self::InvalidResponseMode
60+
| Self::IntoCallbackDestination(_)
61+
| Self::UnknownRedirectUri(_)) => {
62+
GenericError::new(StatusCode::BAD_REQUEST, e).into_response()
6163
}
62-
RouteError::ClientNotFound => {
63-
(StatusCode::BAD_REQUEST, "could not find client").into_response()
64-
}
65-
RouteError::InvalidResponseMode => {
66-
(StatusCode::BAD_REQUEST, "invalid response mode").into_response()
67-
}
68-
RouteError::IntoCallbackDestination(e) => {
69-
(StatusCode::BAD_REQUEST, e.to_string()).into_response()
70-
}
71-
RouteError::UnknownRedirectUri(e) => (
72-
StatusCode::BAD_REQUEST,
73-
format!("Invalid redirect URI ({e})"),
74-
)
75-
.into_response(),
76-
};
77-
78-
(sentry_event_id, response).into_response()
64+
}
7965
}
8066
}
8167

0 commit comments

Comments
 (0)