From 81844145f73bad93435c68a4e7f1d231ec9d9eb4 Mon Sep 17 00:00:00 2001
From: Mohammed Alotaibi
Date: Sun, 28 Jul 2024 13:08:28 +0300
Subject: [PATCH] fix: Fix concatenation issue in `StatusError` display (#841)
Signed-off-by: Awiteb
---
crates/core/src/http/errors/status_error.rs | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/crates/core/src/http/errors/status_error.rs b/crates/core/src/http/errors/status_error.rs
index 705bb137c..f0b58f90d 100644
--- a/crates/core/src/http/errors/status_error.rs
+++ b/crates/core/src/http/errors/status_error.rs
@@ -1,5 +1,5 @@
use std::error::Error as StdError;
-use std::fmt::{self, Debug, Display, Formatter};
+use std::fmt::{self, Debug, Display, Formatter, Write};
use crate::http::{ResBody, StatusCode};
@@ -192,12 +192,14 @@ impl StdError for StatusError {}
impl Display for StatusError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
- write!(f, "code: {}", self.code)?;
- write!(f, "name: {}", self.name)?;
- write!(f, "brief: {:?}", self.brief)?;
- write!(f, "detail: {:?}", self.detail)?;
- write!(f, "cause: {:?}", self.cause)?;
- Ok(())
+ let mut str_error = format!("code: {} name: {} brief: {}", self.code, self.name, self.brief);
+ if let Some(detail) = &self.detail {
+ write!(&mut str_error, " detail: {}", detail)?;
+ }
+ if let Some(cause) = &self.cause {
+ write!(&mut str_error, " cause: {}", cause)?;
+ }
+ f.write_str(&str_error)
}
}