This commit is contained in:
Andras Schmelczer 2025-03-29 14:04:06 +00:00
parent bb5a0bde3a
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 serde::{Deserialize, Serialize};

View file

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