refactor: enhance logging and error handling in API endpoints and HTTP server

This commit is contained in:
Lloyd
2026-06-25 21:26:29 +01:00
parent 1a6e09f63d
commit 42cd75e6b0
5 changed files with 54 additions and 2 deletions
+24
View File
@@ -1,5 +1,6 @@
import io
import logging
import sys
from pathlib import Path
from types import SimpleNamespace
@@ -47,6 +48,29 @@ def test_log_buffer_emit_redacts_sensitive_values():
assert "raw_message" not in entry
def test_log_buffer_emit_includes_exception_text_without_crashing():
buf = hs.LogBuffer(max_lines=5)
try:
raise RuntimeError("boom password=secret123")
except RuntimeError:
rec = logging.LogRecord(
"x",
logging.ERROR,
__file__,
20,
"failure while sending advert",
(),
sys.exc_info(),
)
buf.emit(rec)
assert len(buf.logs) == 1
assert "exception" in buf.logs[0]
assert "RuntimeError" in buf.logs[0]["exception"]
assert "secret123" not in buf.logs[0]["exception"]
def test_doc_endpoint_routes_and_openapi_json_paths(monkeypatch):
api = SimpleNamespace(docs=lambda: "docs-html")
doc = hs.DocEndpoint(api)