mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-09 21:43:05 +09:00
Tracing issue #101 turned up that a panel failing to serve its own agent installer left no diagnostic trail at all. The backend had exactly one error handler -- the 404/SPA one -- no 500 or HTTPException handler, and nothing anywhere configured logging, while only 2 of 100 app/api modules ever call logger.error. Adds: - an errorhandler(500) that logs the unhandled exception with its method and path and returns JSON. Flask routes here only when it is not propagating, so pytest and the dev server still re-raise with a full traceback. - an errorhandler(HTTPException) so framework-generated errors under /api/ (405 from the router, 413, abort()) return JSON instead of Werkzeug's HTML page to clients that are parsing JSON. Non-API paths keep the HTML page, and the more specific 404/500 handlers still win for those codes. - _configure_logging(): a stderr handler with a timestamp/level/logger-name formatter, level from LOG_LEVEL. Services across the codebase log through logging.getLogger(__name__); with no root handler those records fell through to logging's last-resort handler -- WARNING and above only, unformatted, INFO dropped on the floor. Two things the container run caught while writing this: Flask's default handler has to come off app.logger or every record prints twice (once as %(module)s via Flask's handler, once as %(name)s via ours, both reaching stderr through propagation), and the level must not key off DEBUG alone -- TestingConfig sets DEBUG=True, which would have moved the whole test suite to DEBUG logging as a side effect. Both are pinned by tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>