better error handling in isync functions
This commit is contained in:
parent
b2e8ad58d5
commit
3326ee886b
50
src/lib.rs
50
src/lib.rs
@ -53,6 +53,12 @@ fn sha256hexhash(data: Vec<u8>) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn isync_compare_hashes() -> bool {
|
pub async fn isync_compare_hashes() -> bool {
|
||||||
|
/*!
|
||||||
|
* \brief compare local hash to remote hash
|
||||||
|
* \return true if hashes are equal
|
||||||
|
* \return false if hashes are not equal
|
||||||
|
* \return true if error
|
||||||
|
*/
|
||||||
let hash = sha256hexhash(export_data().unwrap());
|
let hash = sha256hexhash(export_data().unwrap());
|
||||||
|
|
||||||
let token = get_token();
|
let token = get_token();
|
||||||
@ -62,16 +68,31 @@ pub async fn isync_compare_hashes() -> bool {
|
|||||||
let req = client.get("https://ipass.ipost.rocks/hash")
|
let req = client.get("https://ipass.ipost.rocks/hash")
|
||||||
.header("ipass-auth-token", token)
|
.header("ipass-auth-token", token)
|
||||||
.timeout(std::time::Duration::from_secs(3))
|
.timeout(std::time::Duration::from_secs(3))
|
||||||
.build().unwrap();
|
.build();
|
||||||
let res = client.execute(req).await.unwrap();
|
if let Ok(req) = req {
|
||||||
let body = res.json::<HashRes>().await.unwrap();
|
let res = client.execute(req).await;
|
||||||
|
if let Ok(res) = res {
|
||||||
|
let body = res.json::<HashRes>().await;
|
||||||
|
if let Ok(body) = body {
|
||||||
if body.success {
|
if body.success {
|
||||||
println!("Hash: {} {}", hash, body.hash);
|
//println!("Hash: {} {}", hash, body.hash);
|
||||||
body.hash == hash
|
body.hash == hash
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Error: {}", body.errorcode);
|
eprintln!("Error: {}", body.errorcode);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error: {}", body.err().unwrap());
|
||||||
|
true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error: {}", res.err().unwrap());
|
||||||
|
true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error: {}", req.err().unwrap());
|
||||||
|
true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("No token found!");
|
eprintln!("No token found!");
|
||||||
@ -89,9 +110,12 @@ pub async fn isync_get() -> bool {
|
|||||||
let req = client.get("https://ipass.ipost.rocks/saved")
|
let req = client.get("https://ipass.ipost.rocks/saved")
|
||||||
.header("ipass-auth-token", token)
|
.header("ipass-auth-token", token)
|
||||||
.timeout(std::time::Duration::from_secs(3))
|
.timeout(std::time::Duration::from_secs(3))
|
||||||
.build().unwrap();
|
.build();
|
||||||
let res = client.execute(req).await.unwrap();
|
if let Ok(req) = req {
|
||||||
let body = res.json::<Saved>().await.unwrap();
|
let res = client.execute(req).await;
|
||||||
|
if let Ok(res) = res {
|
||||||
|
let body = res.json::<Saved>().await;
|
||||||
|
if let Ok(body) = body {
|
||||||
if body.success {
|
if body.success {
|
||||||
println!("new hash: {}",sha256hexhash(body.data.clone()));
|
println!("new hash: {}",sha256hexhash(body.data.clone()));
|
||||||
File::create(get_ipass_folder()+"temp.ipassx").unwrap().write_all(&body.data).unwrap();
|
File::create(get_ipass_folder()+"temp.ipassx").unwrap().write_all(&body.data).unwrap();
|
||||||
@ -105,6 +129,18 @@ pub async fn isync_get() -> bool {
|
|||||||
eprintln!("Error: {}", body.errorcode);
|
eprintln!("Error: {}", body.errorcode);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error: {}", body.err().unwrap());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error: {}", res.err().unwrap());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("Error: {}", req.err().unwrap());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("No token found!");
|
eprintln!("No token found!");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user