feat: honor verbose flag in request errors
This commit is contained in:
parent
245a7e1f88
commit
9b89845280
1 changed files with 16 additions and 2 deletions
|
|
@ -4,6 +4,7 @@ from typing import Any
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
import keyring
|
import keyring
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
from .config import get_effective_config, load_config
|
from .config import get_effective_config, load_config
|
||||||
from .errors import AuthError, NetworkError, ServerError
|
from .errors import AuthError, NetworkError, ServerError
|
||||||
|
|
@ -248,11 +249,24 @@ def handle_request_error(error: Exception) -> None:
|
||||||
url_msg = f" (URL: {request_url!s})"
|
url_msg = f" (URL: {request_url!s})"
|
||||||
except Exception:
|
except Exception:
|
||||||
url_msg = ""
|
url_msg = ""
|
||||||
|
verbose_note = " Use --verbose for details." if _is_verbose_enabled() else ""
|
||||||
raise NetworkError(
|
raise NetworkError(
|
||||||
f"Request failed: {error}{url_msg}\n"
|
f"Request failed: {error}{url_msg}\n"
|
||||||
"Check your network connection and server configuration. "
|
f"Check your network connection and server configuration.{verbose_note}"
|
||||||
"Use --verbose to see more details."
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Bubble up unknown errors unchanged (e.g., typer.Exit for graceful exits)
|
# Bubble up unknown errors unchanged (e.g., typer.Exit for graceful exits)
|
||||||
raise error
|
raise error
|
||||||
|
|
||||||
|
|
||||||
|
def _is_verbose_enabled() -> bool:
|
||||||
|
"""Return True if the current Typer context has verbose/debug enabled."""
|
||||||
|
try:
|
||||||
|
import typer
|
||||||
|
|
||||||
|
ctx = typer.get_current_context(silent=True)
|
||||||
|
if ctx and isinstance(ctx.obj, dict):
|
||||||
|
return bool(ctx.obj.get("verbose"))
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
return False
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue