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,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()))