diff --git a/src/api_client.rs b/src/api_client.rs index 98fbab7..3e9f350 100644 --- a/src/api_client.rs +++ b/src/api_client.rs @@ -1,3 +1,5 @@ +use std::process; + use reqwest::Url; use serde_json::Value; @@ -12,7 +14,10 @@ pub struct ApiClient { impl ApiClient { pub fn new() -> Self { Self { - api_key: token::read_api_key(), + api_key: token::read_api_key().unwrap_or_else(|err| { + eprintln!("Unable to read from '.token' file"); + process::exit(1); + }), base_uri: String::from("https://www.virustotal.com/api/v3"), client: reqwest::blocking::Client::new(), } diff --git a/src/api_client/token.rs b/src/api_client/token.rs index 9c81837..54fd531 100644 --- a/src/api_client/token.rs +++ b/src/api_client/token.rs @@ -1,7 +1,8 @@ +use std::io; use std::fs::read_to_string; -pub fn read_api_key() -> String { - let api_key = read_to_string(".token").expect("Unable to read from '.token' file"); +pub fn read_api_key() -> io::Result { + let api_key = read_to_string(".token")?; - api_key.trim().to_string() + Ok(api_key.trim().to_string()) }