added errors to upload when tilera breaks the api and makes it return nonsense
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
LordMZTE 2021-06-07 11:18:51 +02:00
parent d7c0831c85
commit a4d66b1fbe

View file

@ -1,5 +1,5 @@
use crate::util;
use anyhow::Result;
use anyhow::{Result, bail};
use jm_client_core::{api::UpResp, JMClient};
use log::info;
use reqwest::{
@ -39,7 +39,18 @@ pub async fn run(
let status = res.status();
// TODO move into JMClient
let res = serde_json::from_slice::<UpResp>(&res.bytes().await?)?;
let bytes = &res.bytes().await?;
let res = if let Ok(res) = serde_json::from_slice::<UpResp>(bytes) {
res
} else {
if let Ok(s) = std::str::from_utf8(bytes) {
bail!("Server responded with unexpected response: {}", s);
} else {
bail!("Server responded with invalid utf8 bytes: {:?}", bytes);
}
};
println!("Server responded with code {}", status);