INNER CODE UNIT · Python
domain_error_handler
Duelion/homebox-companion · server/app.py:362
async def domain_error_handler(request, exc: HomeboxCompanionError):
"""Convert domain exceptions to appropriate HTTP responses.
- Logs with appropriate level and exception chain
- Returns structured JSON with error code and user message
- Includes request-ID in response header for correlation
"""
# Log with appropriate level and include exception chain
log_method = getattr(logger, exc.log_level, logger.error)
log_method(
"{error_code}: {details}",
error_code=exc.error_code,
details=str(exc.to_dict()),
exc_info=exc if exc.log_level == "error" else None,
)
return JSONResponse(
status_code=exc.status_code,