Fix: Use HttpError struct for error handling where a non-compliant string was returned

This commit is contained in:
Laurenz 2024-05-10 20:32:40 +02:00
parent 18b2521a93
commit b5e086bd0a
2 changed files with 4 additions and 5 deletions

View file

@ -10,7 +10,7 @@ use axum::{
use log::*; use log::*;
use tower::Service; use tower::Service;
use crate::storage::DatabaseDriver; use crate::{common::HttpError, storage::DatabaseDriver};
#[derive(Clone)] #[derive(Clone)]
/// State to be used to store the database pool /// State to be used to store the database pool
@ -47,7 +47,7 @@ async fn engine_handler(
} }
} else { } else {
// Otherwise, the mount path could not be found // Otherwise, the mount path could not be found
(StatusCode::NOT_FOUND, "Mount path not found").into_response() HttpError::simple(StatusCode::NOT_FOUND, "Secret engine mount path not found")
} }
} }
@ -66,9 +66,9 @@ async fn call_router(engine: Router, mount_path: String, mut req: Request) -> Re
/// HTTP error response for unknown engine types /// HTTP error response for unknown engine types
/// Occurs when the mount path is found in the database /// Occurs when the mount path is found in the database
/// but the registered is unknown /// but the registered is unknown
fn unknown_engine(engine_type: String) -> (StatusCode, String) { fn unknown_engine(engine_type: String) -> impl IntoResponse {
error!("Engine type {} not implemented", engine_type); error!("Engine type {} not implemented", engine_type);
( HttpError::simple(
StatusCode::INTERNAL_SERVER_ERROR, StatusCode::INTERNAL_SERVER_ERROR,
format!("Engine type {} not implemented", engine_type), format!("Engine type {} not implemented", engine_type),
) )

View file

@ -1,6 +1,5 @@
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use zeroize::ZeroizeOnDrop;
use std::{collections::HashMap, vec}; use std::{collections::HashMap, vec};
pub type KvSecretData = HashMap<String, String>; pub type KvSecretData = HashMap<String, String>;