Skip to content

Commit

Permalink
refactor(cli/auth): uses API error handling helpers (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
KokaKiwi authored Feb 14, 2025
1 parent d4e3a5c commit 02d30ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion crates/cli/src/commands/auth/login.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use anyhow::Result;

use edgee_api_client::ResultExt;

setup_command! {}

pub async fn run(_opts: Options) -> Result<()> {
Expand Down Expand Up @@ -27,7 +29,12 @@ pub async fn run(_opts: Options) -> Result<()> {

let client = edgee_api_client::new().credentials(&creds).connect();

let user = client.get_me().send().await?.into_inner();
let user = client
.get_me()
.send()
.await
.api_context("Could not get user infos")?
.into_inner();
println!("Logged as {} ({})", user.name, user.email);

creds.save()
Expand Down
8 changes: 7 additions & 1 deletion crates/cli/src/commands/auth/whoami.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use edgee_api_client::ResultExt;

setup_command! {}

pub async fn run(_opts: Options) -> anyhow::Result<()> {
Expand All @@ -7,7 +9,11 @@ pub async fn run(_opts: Options) -> anyhow::Result<()> {
creds.check_api_token()?;

let client = edgee_api_client::new().credentials(&creds).connect();
let user = client.get_me().send().await?;
let user = client
.get_me()
.send()
.await
.api_context("Could not get user infos")?;

println!("Logged in as:");
println!(" ID: {}", user.id);
Expand Down

0 comments on commit 02d30ab

Please sign in to comment.