Skip to content

Commit

Permalink
feat: return fixed message for internal error as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Oct 8, 2023
1 parent f102dea commit 4103947
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/common/error/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ pub trait ErrorExt: StackError {
where
Self: Sized,
{
if self.status_code() == StatusCode::Unknown {
"Internal Error".to_owned()
} else {
let error = self.last();
if let Some(external_error) = error.source() {
let external_root = external_error.sources().last().unwrap();

if error.to_string().is_empty() {
format!("{external_root}")
match self.status_code() {
StatusCode::Unknown | StatusCode::Internal => "Internal Error".to_owned(),
_ => {
let error = self.last();
if let Some(external_error) = error.source() {
let external_root = external_error.sources().last().unwrap();

if error.to_string().is_empty() {
format!("{external_root}")
} else {
format!("{error}: {external_root}")
}
} else {
format!("{error}: {external_root}")
format!("{error}")
}
} else {
format!("{error}")
}
}
}
Expand Down

0 comments on commit 4103947

Please sign in to comment.