Skip to content

Commit d58f135

Browse files
committed
style: simplify unwrapping error message
1 parent e391bfc commit d58f135

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/ssh.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,9 @@ async fn unpack_response<T: DeserializeOwned>(response: reqwest::Response) -> Re
192192
internal_message: String,
193193
}
194194

195-
let err = if let Ok(ErrorMessage {
196-
internal_message: message,
197-
}) = serde_json::from_str(&body)
198-
{
199-
anyhow!(message)
200-
} else {
201-
anyhow!("unknown error type.")
202-
};
203-
204-
Err(err)
195+
anyhow::bail!(serde_json::from_str::<ErrorMessage>(&body)
196+
.map(|err| err.internal_message)
197+
.unwrap_or_else(|_| "unknown error type".to_string()))
205198
} else {
206199
serde_json::from_str(&body).map_err(|_| anyhow!("unsupported reply."))
207200
}

0 commit comments

Comments
 (0)