Handle error reading token file

This commit is contained in:
Erwin Boskma 2023-07-03 16:02:23 +02:00
parent 888ea9758b
commit 9148f2b77d
Signed by: erwin
SSH key fingerprint: SHA256:9LmFDe1C6jSrEyqxxvX8NtJBmcbB105XoqyUZF092bg

View file

@ -103,11 +103,15 @@ async fn main() -> Result<()> {
let token = if let Some(token) = token { let token = if let Some(token) = token {
Some(token) Some(token)
} else if let Some(token_file) = token_file { } else if let Some(token_file) = token_file {
if let Ok(mut file) = std::fs::File::open(token_file) { if let Ok(mut file) = std::fs::File::open(token_file.clone()) {
let mut buf = String::new(); let mut buf = String::new();
file.read_to_string(&mut buf).ok(); file.read_to_string(&mut buf).ok();
Some(buf) Some(buf)
} else { } else {
println!(
"Error reading API token file '{}'",
token_file.as_path().display()
);
None None
} }
} else { } else {
@ -130,7 +134,7 @@ async fn main() -> Result<()> {
.insecure(insecure) .insecure(insecure)
.format(format) .format(format)
.build(); .build();
ha.open_connection().await.unwrap(); ha.open_connection().await.unwrap_or(());
} }
} }
Ok(()) Ok(())