HTTP 错误兜底先过滤 message 再退 code,避免空 message 吞掉 code
game_distribution_publish response_data 的 message.or(code).filter 顺序反了,空 message 会连 code 一起丢掉 map_http_error 同类顺序问题一并修正(review 未列,属同一类 bug)
This commit is contained in:
@@ -195,8 +195,8 @@ fn response_data(body: &str) -> Result<Value, String> {
|
||||
if value.get("ok").and_then(Value::as_bool) == Some(false) {
|
||||
let (code, message) = parse_error_payload(body);
|
||||
return Err(message
|
||||
.or(code)
|
||||
.filter(|detail| !detail.trim().is_empty())
|
||||
.or_else(|| code.filter(|detail| !detail.trim().is_empty()))
|
||||
.unwrap_or_else(|| "服务器未返回错误信息".to_string()));
|
||||
}
|
||||
Ok(value.get("data").cloned().unwrap_or(value))
|
||||
@@ -215,8 +215,8 @@ fn map_http_error(status: StatusCode, body: &str, fallback: &str) -> String {
|
||||
);
|
||||
}
|
||||
let detail = message
|
||||
.or(code)
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.or_else(|| code.filter(|value| !value.trim().is_empty()))
|
||||
.unwrap_or_else(|| format!("HTTP {}", status.as_u16()));
|
||||
format!("{fallback}:{detail}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user