Skip to content

Commit 535b3f9

Browse files
committed
Redirect to error page instead of returning server error code
1 parent c2b30f6 commit 535b3f9

File tree

5 files changed

+15
-25
lines changed

5 files changed

+15
-25
lines changed

src/auth/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use authenticated_user::AuthenticatedUser;
77
use axum::routing::post;
88
use axum::{
99
extract::{Query, State},
10-
http::{self, Uri},
10+
http::{Uri},
1111
response::Redirect,
1212
routing::get,
1313
Form, Router,
@@ -143,7 +143,7 @@ impl IntoResponse for CompleteSignInError {
143143
CompleteSignInError::Expired => Redirect::to("/signin").into_response(),
144144
other => {
145145
tracing::error!("Error getting complete sign in page: {}", other);
146-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
146+
Redirect::to("/error").into_response()
147147
}
148148
}
149149
}
@@ -227,7 +227,7 @@ enum CompleteSignUpError {
227227
impl IntoResponse for CompleteSignUpError {
228228
fn into_response(self) -> askama_axum::Response {
229229
tracing::error!("Error completing sign in: {}", self);
230-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
230+
Redirect::to("/error").into_response()
231231
}
232232
}
233233

src/auth/open_id_connect/authentication_response.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use std::sync::Arc;
22

33
use axum::response::{IntoResponse, Redirect};
4-
use axum::{
5-
extract::{Query, State},
6-
http,
7-
};
4+
use axum::extract::{Query, State};
85
use axum_extra::extract::SignedCookieJar;
96
use serde::{Deserialize, Serialize};
107
use url::Url;
@@ -104,7 +101,7 @@ pub(in crate::auth) enum HandleAuthenticationResponseError {
104101
impl IntoResponse for HandleAuthenticationResponseError {
105102
fn into_response(self) -> askama_axum::Response {
106103
tracing::error!("Error handling authentication response: {}", self);
107-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
104+
Redirect::to("/error").into_response()
108105
}
109106
}
110107

src/routes/error.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
use askama::Template;
22

3-
use crate::auth::authenticated_user::AuthenticatedUser;
4-
53
#[derive(Template)]
64
#[template(path = "error.html")]
7-
pub(crate) struct ErrorTemplate {
8-
is_authenticated: bool,
9-
}
5+
pub(crate) struct ErrorTemplate;
106

11-
pub(crate) async fn get_error_page(user: Option<AuthenticatedUser>) -> ErrorTemplate {
12-
ErrorTemplate {
13-
is_authenticated: user.is_some(),
14-
}
7+
pub(crate) async fn get_error_page() -> ErrorTemplate {
8+
ErrorTemplate
159
}

src/routes/survey/attrakdiff.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::AppState;
55
use askama::Template;
66
use askama_axum::IntoResponse;
77
use axum::extract::{Path, State};
8-
use axum::http::{self};
98
use axum::response::Redirect;
109
use axum::Form;
1110
use nanoid::nanoid;
@@ -190,7 +189,7 @@ struct AttrakdiffResultsTemplate {
190189
impl IntoResponse for GetResultsPageError {
191190
fn into_response(self) -> askama_axum::Response {
192191
tracing::error!("Error getting results page: {}", self);
193-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
192+
Redirect::to("/error").into_response()
194193
}
195194
}
196195

src/routes/survey/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use axum::extract::{FromRequest, Path, Request, State};
88
use axum::http::{HeaderMap, HeaderValue};
99
use axum::response::{Redirect, Response};
1010
use axum::routing::{get, post};
11-
use axum::{http, Form, Router};
11+
use axum::{Form, Router};
1212
use reqwest::header::{self, InvalidHeaderValue};
1313
use serde::Deserialize;
1414
use std::fmt::Debug;
@@ -88,7 +88,7 @@ pub(crate) enum GetSurveysPageError {
8888
impl IntoResponse for GetSurveysPageError {
8989
fn into_response(self) -> Response {
9090
tracing::error!("Error getting surveys page: {:?}", self);
91-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
91+
Redirect::to("/error").into_response()
9292
}
9393
}
9494

@@ -115,7 +115,7 @@ enum CreateResponseError {
115115
impl IntoResponse for CreateResponseError {
116116
fn into_response(self) -> Response {
117117
tracing::error!("Error creating response: {:?}", self);
118-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
118+
Redirect::to("/error").into_response()
119119
}
120120
}
121121

@@ -180,7 +180,7 @@ enum GetSurveyError {
180180
impl IntoResponse for GetSurveyError {
181181
fn into_response(self) -> Response {
182182
tracing::error!("Error getting survey: {:?}", self);
183-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
183+
Redirect::to("/error").into_response()
184184
}
185185
}
186186

@@ -230,7 +230,7 @@ pub(super) enum CreateSurveyError {
230230
impl IntoResponse for CreateSurveyError {
231231
fn into_response(self) -> askama_axum::Response {
232232
tracing::error!("Error creating survey: {}", self);
233-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
233+
Redirect::to("/error").into_response()
234234
}
235235
}
236236

@@ -366,7 +366,7 @@ enum DownloadResultsError {
366366
impl IntoResponse for DownloadResultsError {
367367
fn into_response(self) -> askama_axum::Response {
368368
tracing::error!("Error downloading results: {}", self);
369-
http::StatusCode::INTERNAL_SERVER_ERROR.into_response()
369+
Redirect::to("/error").into_response()
370370
}
371371
}
372372

0 commit comments

Comments
 (0)