feat: refactored error handling

This commit is contained in:
Per Stark
2025-01-01 23:26:41 +01:00
parent 796bbc0225
commit 519f6c6eb1
25 changed files with 439 additions and 293 deletions

View File

@@ -1,4 +1,8 @@
use crate::{error::ApiError, server::AppState, storage::types::file_info::FileInfo};
use crate::{
error::{ApiError, AppError},
server::AppState,
storage::types::file_info::FileInfo,
};
use axum::{extract::State, response::IntoResponse, Json};
use axum_typed_multipart::{FieldData, TryFromMultipart, TypedMultipart};
use serde_json::json;
@@ -21,7 +25,9 @@ pub async fn upload_handler(
info!("Received an upload request");
// Process the file upload
let file_info = FileInfo::new(input.file, &state.surreal_db_client).await?;
let file_info = FileInfo::new(input.file, &state.surreal_db_client)
.await
.map_err(AppError::from)?;
// Prepare the response JSON
let response = json!({

View File

@@ -1,5 +1,5 @@
use crate::{
error::ApiError,
error::{ApiError, AppError},
ingress::types::ingress_input::{create_ingress_objects, IngressInput},
server::AppState,
storage::types::user::User,
@@ -22,7 +22,7 @@ pub async fn ingress_handler(
.map(|object| state.rabbitmq_producer.publish(object))
.collect();
try_join_all(futures).await?;
try_join_all(futures).await.map_err(AppError::from)?;
Ok(StatusCode::OK)
}

View File

@@ -1,21 +1,28 @@
use axum::{extract::State, http::StatusCode, response::IntoResponse};
use minijinja::context;
use tracing::{info, Instrument};
use tracing::info;
use crate::{error::ApiError, server::AppState};
use crate::{
error::{ApiError, AppError},
server::AppState,
};
pub async fn queue_length_handler(
State(state): State<AppState>,
) -> Result<impl IntoResponse, ApiError> {
info!("Getting queue length");
let queue_length = state.rabbitmq_consumer.get_queue_length().await?;
let queue_length = state
.rabbitmq_consumer
.get_queue_length()
.await
.map_err(AppError::from)?;
info!("Queue length: {}", queue_length);
state
.mailer
.send_email_verification("per@starks.cloud", "1001010", &state.templates)?;
.send_email_verification("per@starks.cloud", "1001010", &state.templates)
.map_err(AppError::from)?;
// Return the queue length with a 200 OK status
Ok((StatusCode::OK, queue_length.to_string()))