feat(errors): provide readable Redmine API error messages

- Introduce RedmineAPIError with human-friendly messages.
- Distinguish AuthError, ForbiddenError, HTTP status codes, timeouts
  and connection errors in client.py.
- Update CLI to print the readable message instead of generic
  "Redmine API error: ...".
- Log original exception with traceback when --debug is enabled.
- Add tests for all error paths and CLI output.

Closes #39
This commit is contained in:
Кокос Артем Николаевич
2026-06-29 14:58:21 +07:00
parent 222d31730e
commit f80f3a8b52
4 changed files with 195 additions and 10 deletions

View File

@@ -7,7 +7,7 @@ from datetime import datetime
from typing import List, Optional
from . import __version__
from .client import fetch_issues_with_spent_time
from .client import RedmineAPIError, fetch_issues_with_spent_time
from .config import Config
from .formatters.factory import get_console_formatter, get_formatter_by_extension
from .report_builder import build_grouped_report, calculate_summary
@@ -106,8 +106,13 @@ def main(argv: Optional[List[str]] = None) -> int:
try:
issue_hours = fetch_issues_with_spent_time(from_date, to_date)
except RedmineAPIError as e:
print(f"{e.message}", file=sys.stderr)
if args.debug and e.original is not None:
logging.exception("Original Redmine API error")
return 1
except Exception as e:
print(f"Redmine API error: {e}", file=sys.stderr)
print(f"Unexpected error: {e}", file=sys.stderr)
return 1
if issue_hours is None: