fix: report non-decodable errors correctly (#1915)

This commit is contained in:
Ellie Huxtable 2024-04-02 16:52:45 +01:00 committed by GitHub
parent f814f62267
commit bb0ea6c516
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -157,13 +157,17 @@ async fn handle_resp_error(resp: Response) -> Result<Response> {
);
}
if !status.is_success() {
if let Ok(error) = resp.json::<ErrorResponse>().await {
let reason = error.reason;
if status.is_client_error() {
let error = resp.json::<ErrorResponse>().await?.reason;
bail!("Could not fetch history, client error: {error}.")
} else if status.is_server_error() {
let error = resp.json::<ErrorResponse>().await?.reason;
bail!("There was an error with the atuin sync service: {error}.\nIf the problem persists, contact the host")
} else if !status.is_success() {
bail!("Could not fetch history, client error {status}: {reason}.")
}
bail!("There was an error with the atuin sync service, server error {status}: {reason}.\nIf the problem persists, contact the host")
}
bail!("There was an error with the atuin sync service: Status {status:?}.\nIf the problem persists, contact the host")
}