Skip to content

Commit 30bb4d2

Browse files
authored
chore: Fix suppressed error detail (#196)
1 parent 533c686 commit 30bb4d2

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

cloudsmith_cli/cli/commands/login.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ def login(ctx, opts, login, password): # pylint: disable=redefined-outer-name
157157
)
158158
ctx.exit(1)
159159

160-
except cloudsmith_api.rest.ApiException:
160+
except cloudsmith_api.rest.ApiException as e:
161161
click.echo("\r\033[K", nl=False)
162-
click.secho("Authentication failed: Invalid username/password.", fg="red")
162+
click.secho(f"Authentication failed: {str(e)}", fg="red")
163163
ctx.exit(1)
164164

165165
click.secho("OK", fg="green")

cloudsmith_cli/core/api/user.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,20 @@ def get_user_token(login, password, totp_token=None, two_factor_token=None):
3939
ratelimits.maybe_rate_limit(client, headers)
4040
return data.token
4141
except ApiException as e:
42-
# Check if this is a 2FA required response
43-
if e.status == 422:
42+
# Check for 2FA requirement
43+
if e.status == 422 and e.body:
4444
try:
4545
response_data = json.loads(e.body)
4646
if response_data.get("two_factor_required"):
4747
two_factor_token = response_data.get("two_factor_token")
48-
4948
# Raise custom exception for 2FA requirement
5049
raise TwoFactorRequiredException(two_factor_token)
5150
except (ValueError, KeyError):
52-
# If we can't parse as JSON or doesn't have expected structure
5351
pass
54-
raise
52+
53+
# If not 2FA, use the context manager to handle other API exceptions
54+
with catch_raise_api_exception():
55+
raise
5556

5657

5758
def get_user_brief():

0 commit comments

Comments
 (0)