This commit is contained in:
Andras Schmelczer 2025-03-29 14:04:06 +00:00
commit 0311883a16
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
3 changed files with 9 additions and 9 deletions

View file

@ -1,5 +1,3 @@
use std::default;
use rand::{Rng as _, distributions::Alphanumeric, thread_rng}; use rand::{Rng as _, distributions::Alphanumeric, thread_rng};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,3 +1,5 @@
use std::fmt::Display;
use aide::OperationOutput; use aide::OperationOutput;
use axum::{ use axum::{
Json, Json,
@ -49,16 +51,16 @@ pub struct SerializedError {
pub causes: Vec<String>, pub causes: Vec<String>,
} }
impl ToString for SerializedError { impl Display for SerializedError {
fn to_string(&self) -> String { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut result = self.message.clone();
if !self.causes.is_empty() { if !self.causes.is_empty() {
result.push_str("\nCauses:\n"); write!(f, "\nCauses:\n")?;
for cause in &self.causes { for cause in &self.causes {
result.push_str(&format!("- {}\n", cause)); write!(f, "{}", &format!("- {cause}\n"))?;
} }
} }
result
Ok(())
} }
} }

View file

@ -29,7 +29,7 @@ async fn main() -> ExitCode {
match result { match result {
Ok(()) => ExitCode::SUCCESS, Ok(()) => ExitCode::SUCCESS,
Err(e) => { Err(e) => {
eprintln!("{}", e.serialize().to_string()); eprintln!("{}", e.serialize());
ExitCode::FAILURE ExitCode::FAILURE
} }
} }