INNER CODE UNIT · Python
not_found_handler
alihaskar/pycharting · src/pycharting/core/server.py:218
async def not_found_handler(request: Request, _exc: Exception) -> JSONResponse:
"""Handle 404 errors."""
return JSONResponse(status_code=404, content={"error": "Not found", "path": str(request.url.path)})
@app.exception_handler(500)
async def server_error_handler(_request: Request, exc: Exception) -> JSONResponse: # pragma: no cover
"""Handle 500 errors."""
logger.error(f"Server error: {exc}")
return JSONResponse(status_code=500, content={"error": "Internal server error"})
return app
def run_server(
host: str = "127.0.0.1",
port: int | None = None,
auto_port: bool = True,
reload: bool = False,