refactor: adjust outermost error message (#859)

* refactor: adjust outermost error message

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* fix clippy

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

* preserve tonic status code

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>

Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
Ruihang Xia
2023-01-10 17:28:27 +08:00
committed by GitHub
parent 5fb417ec7c
commit 32d51947a4
9 changed files with 49 additions and 24 deletions

View File

@@ -347,11 +347,11 @@ impl From<Error> for tonic::Status {
// If either of the status_code or error msg cannot convert to valid HTTP header value
// (which is a very rare case), just ignore. Client will use Tonic status code and message.
if let Ok(code) = HeaderValue::from_bytes((err.status_code() as u32).to_string().as_bytes())
{
if let Ok(code) = HeaderValue::from_bytes(err.status_code().to_string().as_bytes()) {
headers.insert(INNER_ERROR_CODE, code);
}
if let Ok(err_msg) = HeaderValue::from_bytes(err.to_string().as_bytes()) {
let root_error = err.iter_chain().last().unwrap();
if let Ok(err_msg) = HeaderValue::from_bytes(root_error.to_string().as_bytes()) {
headers.insert(INNER_ERROR_MSG, err_msg);
}