Handle error reading token file
This commit is contained in:
parent
888ea9758b
commit
9148f2b77d
1 changed files with 6 additions and 2 deletions
|
@ -103,11 +103,15 @@ async fn main() -> Result<()> {
|
|||
let token = if let Some(token) = token {
|
||||
Some(token)
|
||||
} 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();
|
||||
file.read_to_string(&mut buf).ok();
|
||||
Some(buf)
|
||||
} else {
|
||||
println!(
|
||||
"Error reading API token file '{}'",
|
||||
token_file.as_path().display()
|
||||
);
|
||||
None
|
||||
}
|
||||
} else {
|
||||
|
@ -130,7 +134,7 @@ async fn main() -> Result<()> {
|
|||
.insecure(insecure)
|
||||
.format(format)
|
||||
.build();
|
||||
ha.open_connection().await.unwrap();
|
||||
ha.open_connection().await.unwrap_or(());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in a new issue