Files
João MouraandClaude Opus 5.5 eb66d6207a fix(cli): show amp's reason on a 401 and let the run app's deploy log in again (#8594)
* fix(cli): show amp's reason on a 401 and let the run app's deploy log in again

A 401 from AMP went through `_validate_response` as a generic API failure:
only the error code ("bad_credentials") was printed, AMP's message was
dropped, and a bare SystemExit made the run app's Deploy print "Deploy
failed" without offering a login. A 401 now prints AMP's own message and a
`crewai login` hint, then raises `AuthenticationRequiredError` (still a
SystemExit, same exit code), so the run app's Deploy offers the login once
and retries once, as it does for a missing token. The saved token is not
cleared: AMP also answers 401 for accounts a new login cannot fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): handle a 401 before parsing its body and exit 1 on it

A 401 whose body was not JSON (a proxy or gateway page, or an empty body)
took the parse-failure path, so the run app's Deploy printed "Deploy failed"
and never offered a login. The 401 check now runs before the JSON parse and
falls back to the raw body for the reason, so a JSON body with neither
`message` nor `error` no longer prints "None". The 401 now raises
AuthenticationRequiredError(1), matching the missing-token case in #8590,
so a token AMP rejects and a missing token exit the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 01:43:54 -03:00
..