mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-21 08:21:25 +02:00
feat: refactored error handling
This commit is contained in:
@@ -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!({
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()))
|
||||
|
||||
Reference in New Issue
Block a user