@smbcloud / cli / commits / 54de0eb

no unwrap

Seto Elkahfi committed Apr 10, 2023 at 01:20 UTC 54de0eb7998dae68c54a111fda0d5ee9d95a8f50
1 file changed +5 -2
src/projects/crud/mod.rs
+5 -2
@@ -45,7 +45,7 @@ pub async fn get_all() -> Result<Vec<Project>> {
45
46 pub async fn create_project(project: ProjectCreate) -> Result<Project> {
47 // Get current token
48 - let token = get_token().await.unwrap();
48 + let token = get_token().await?;
49
50 let response = Client::new()
51 .post([BASE_URL, "v1/projects"].join(""))
@@ -115,7 +115,10 @@ pub async fn delete_project(id: String) -> Result<()> {
115 async fn get_token() -> Result<String> {
116 if let Some(mut path) = dirs::home_dir() {
117 path.push(".smb/token");
118 - std::fs::read_to_string(path).map_err(|e| anyhow!(e))
118 + std::fs::read_to_string(path).map_err(|e| {
119 + debug!("Error while reading token: {}", &e);
120 + anyhow!("Are you logged in?")
121 + })
122 } else {
123 Err(anyhow!("Failed to get home directory."))
124 }