Skip to content

Commit 782d6b2

Browse files
authored
πŸ§‘β€πŸ’» Handle HTTP errors when streaming build logs (#65)
1 parent ccdd419 commit 782d6b2

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

β€Žsrc/fastapi_cloud_cli/commands/deploy.pyβ€Ž

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -345,42 +345,43 @@ def _wait_for_deployment(
345345
with toolkit.progress(
346346
next(messages), inline_logs=True, lines_to_show=20
347347
) as progress:
348-
for line in _stream_build_logs(deployment.id):
349-
time_elapsed = time.monotonic() - started_at
348+
with handle_http_errors(progress=progress):
349+
for line in _stream_build_logs(deployment.id):
350+
time_elapsed = time.monotonic() - started_at
350351

351-
data = json.loads(line)
352+
data = json.loads(line)
352353

353-
if "message" in data:
354-
progress.log(Text.from_ansi(data["message"].rstrip()))
354+
if "message" in data:
355+
progress.log(Text.from_ansi(data["message"].rstrip()))
355356

356-
if data.get("type") == "complete":
357-
progress.log("")
358-
progress.log(
359-
f"πŸ” Ready the chicken! Your app is ready at [link={deployment.url}]{deployment.url}[/link]"
360-
)
357+
if data.get("type") == "complete":
358+
progress.log("")
359+
progress.log(
360+
f"πŸ” Ready the chicken! Your app is ready at [link={deployment.url}]{deployment.url}[/link]"
361+
)
361362

362-
progress.log("")
363+
progress.log("")
363364

364-
progress.log(
365-
f"You can also check the app logs at [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
366-
)
365+
progress.log(
366+
f"You can also check the app logs at [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
367+
)
367368

368-
break
369+
break
369370

370-
if data.get("type") == "failed":
371-
progress.log("")
372-
progress.log(
373-
f"πŸ˜” Oh no! Something went wrong. Check out the logs at [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
374-
)
375-
raise typer.Exit(1)
371+
if data.get("type") == "failed":
372+
progress.log("")
373+
progress.log(
374+
f"πŸ˜” Oh no! Something went wrong. Check out the logs at [link={deployment.dashboard_url}]{deployment.dashboard_url}[/link]"
375+
)
376+
raise typer.Exit(1)
376377

377-
if time_elapsed > 30:
378-
messages = cycle(LONG_WAIT_MESSAGES) # pragma: no cover
378+
if time_elapsed > 30:
379+
messages = cycle(LONG_WAIT_MESSAGES) # pragma: no cover
379380

380-
if (time.monotonic() - last_message_changed_at) > 2:
381-
progress.title = next(messages) # pragma: no cover
381+
if (time.monotonic() - last_message_changed_at) > 2:
382+
progress.title = next(messages) # pragma: no cover
382383

383-
last_message_changed_at = time.monotonic() # pragma: no cover
384+
last_message_changed_at = time.monotonic() # pragma: no cover
384385

385386

386387
def _setup_environment_variables(toolkit: RichToolkit, app_id: str) -> None:

β€Žsrc/fastapi_cloud_cli/utils/api.pyβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def __init__(self) -> None:
1313

1414
super().__init__(
1515
base_url=settings.base_api_url,
16+
timeout=httpx.Timeout(20),
1617
headers={
1718
"Authorization": f"Bearer {token}",
1819
"User-Agent": f"fastapi-cloud-cli/{__version__}",

0 commit comments

Comments
Β (0)