use dedicated error page
I can't re-display the form as I'd like to becuase I don't have access to the CSRF token when rendering the page from the error hander.
This commit is contained in:
parent
b1bf7cb581
commit
c7500ae6a3
3 changed files with 45 additions and 12 deletions
|
@ -22,6 +22,8 @@ use crate::server::{
|
|||
AppState,
|
||||
};
|
||||
|
||||
use super::ErrorPage;
|
||||
|
||||
pub fn build() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/signup", get(signup_page).post(signup))
|
||||
|
@ -174,7 +176,7 @@ pub enum SignupError {
|
|||
|
||||
impl IntoResponse for SignupError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
let (status, message) = match self {
|
||||
SignupError::InvalidEmail => (StatusCode::BAD_REQUEST, "Invalid Email"),
|
||||
SignupError::CsrfValidationFailed => {
|
||||
(StatusCode::BAD_REQUEST, "CSRF Validation Failed, Try Again")
|
||||
|
@ -183,8 +185,15 @@ impl IntoResponse for SignupError {
|
|||
error!(?e, "returning INTERNAL SERVER ERROR");
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Unknown Error")
|
||||
}
|
||||
}
|
||||
.into_response()
|
||||
};
|
||||
|
||||
(
|
||||
status,
|
||||
ErrorPage {
|
||||
error: message.to_string(),
|
||||
},
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,9 +320,8 @@ impl IntoResponse for LoginError {
|
|||
|
||||
(
|
||||
status,
|
||||
LoginPage {
|
||||
error: Some(message.to_string()),
|
||||
csrf_token: "".to_string(),
|
||||
ErrorPage {
|
||||
error: message.to_string(),
|
||||
},
|
||||
)
|
||||
.into_response()
|
||||
|
@ -374,7 +382,7 @@ pub enum LogoutError {
|
|||
|
||||
impl IntoResponse for LogoutError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
let (status, message) = match self {
|
||||
LogoutError::NotLoggedIn => (StatusCode::UNAUTHORIZED, "Unknown User"),
|
||||
LogoutError::CsrfValidationFailed => {
|
||||
(StatusCode::BAD_REQUEST, "CSRF Validation Failed, Try Again")
|
||||
|
@ -383,8 +391,15 @@ impl IntoResponse for LogoutError {
|
|||
error!(?e, "returning INTERNAL SERVER ERROR");
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Unknown Error")
|
||||
}
|
||||
}
|
||||
.into_response()
|
||||
};
|
||||
|
||||
(
|
||||
status,
|
||||
ErrorPage {
|
||||
error: message.to_string(),
|
||||
},
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,7 +471,7 @@ pub enum SignupConfirmError {
|
|||
|
||||
impl IntoResponse for SignupConfirmError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self {
|
||||
let (status, message) = match self {
|
||||
SignupConfirmError::InvalidToken => (StatusCode::UNAUTHORIZED, "Unknown User"),
|
||||
SignupConfirmError::CsrfValidationFailed => {
|
||||
(StatusCode::BAD_REQUEST, "CSRF Validation Failed, Try Again")
|
||||
|
@ -465,7 +480,14 @@ impl IntoResponse for SignupConfirmError {
|
|||
error!(?e, "returning INTERNAL SERVER ERROR");
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, "Unknown Error")
|
||||
}
|
||||
}
|
||||
.into_response()
|
||||
};
|
||||
|
||||
(
|
||||
status,
|
||||
ErrorPage {
|
||||
error: message.to_string(),
|
||||
},
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,3 +29,9 @@ async fn homepage(user: Auth) -> Homepage {
|
|||
is_logged_in: user.user.is_some(),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "error.html")]
|
||||
struct ErrorPage {
|
||||
error: String,
|
||||
}
|
||||
|
|
5
templates/error.html
Normal file
5
templates/error.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<title>Error</title>
|
||||
<p class="error">{{error}}</p>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue