11import logging
22from typing import Any
33
4- import httpx
5- import typer
64from rich import print
5+ from rich_toolkit .progress import Progress
76
87from fastapi_cli .utils .api import APIClient
98from fastapi_cli .utils .auth import is_logged_in
9+ from fastapi_cli .utils .cli import handle_http_errors
1010
1111logger = logging .getLogger (__name__ )
1212
@@ -17,29 +17,10 @@ def whoami() -> Any:
1717 return
1818
1919 with APIClient () as client :
20- try :
21- response = client .get ("/users/me" )
22- except httpx .ReadTimeout :
23- print (
24- "[red]Error[/]: The request to the FastAPI Cloud server timed out. Please try again later."
25- )
26- raise typer .Exit (code = 1 ) from None
27-
28- if response .status_code in (401 , 403 ):
29- print (
30- "[red]Error[/]: The specified token is not valid. Use [blue]`fastapi login`[/] to generate a new token."
31- )
32- raise typer .Exit (code = 1 ) from None
33-
34- try :
35- response .raise_for_status ()
36- except httpx .HTTPError as e :
37- logger .debug ("Error: %s" , e )
38-
39- print (
40- "[red]Error[/]: Something went wrong while contacting the FastAPI Cloud server. Please try again later."
41- )
42- raise typer .Exit (code = 1 ) from None
20+ with Progress (title = "⚡Fetching profile" , transient = True ) as progress :
21+ with handle_http_errors (progress , message = "" ):
22+ response = client .get ("/users/me" )
23+ response .raise_for_status ()
4324
4425 data = response .json ()
4526
0 commit comments