mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-29 12:17:08 +02:00
feat: refactored error handling
This commit is contained in:
@@ -10,7 +10,11 @@ use axum_session_surreal::SessionSurrealPool;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use surrealdb::{engine::any::Any, Surreal};
|
||||
|
||||
use crate::{error::ApiError, server::AppState, storage::types::user::User};
|
||||
use crate::{
|
||||
error::{AppError, HtmlError},
|
||||
server::AppState,
|
||||
storage::types::user::User,
|
||||
};
|
||||
|
||||
use super::{render_block, render_template};
|
||||
|
||||
@@ -29,7 +33,7 @@ pub async fn show_signup_form(
|
||||
State(state): State<AppState>,
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
HxBoosted(boosted): HxBoosted,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
) -> Result<impl IntoResponse, HtmlError> {
|
||||
if auth.is_authenticated() {
|
||||
return Ok(Redirect::to("/").into_response());
|
||||
}
|
||||
@@ -38,9 +42,15 @@ pub async fn show_signup_form(
|
||||
"auth/signup_form.html",
|
||||
"body",
|
||||
PageData {},
|
||||
state.templates,
|
||||
)?,
|
||||
false => render_template("auth/signup_form.html", PageData {}, state.templates)?,
|
||||
state.templates.clone(),
|
||||
)
|
||||
.map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?,
|
||||
false => render_template(
|
||||
"auth/signup_form.html",
|
||||
PageData {},
|
||||
state.templates.clone(),
|
||||
)
|
||||
.map_err(|e| HtmlError::new(AppError::from(e), state.templates.clone()))?,
|
||||
};
|
||||
|
||||
Ok(output.into_response())
|
||||
@@ -50,7 +60,7 @@ pub async fn process_signup_and_show_verification(
|
||||
State(state): State<AppState>,
|
||||
auth: AuthSession<User, String, SessionSurrealPool<Any>, Surreal<Any>>,
|
||||
Form(form): Form<SignupParams>,
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
) -> Result<impl IntoResponse, HtmlError> {
|
||||
let user = match User::create_new(form.email, form.password, &state.surreal_db_client).await {
|
||||
Ok(user) => user,
|
||||
Err(_) => {
|
||||
|
||||
Reference in New Issue
Block a user