python runtime_error ai_generated true

starlette.exceptions.HTTPException: 500 Internal Server Error

ID: python/starlette-http-exception-handling

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2025-01-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

服务器内部发生未捕获的异常,导致 500 错误。

generic

中文

服务器内部发生未捕获的异常,导致 500 错误。

Workarounds

  1. 95% success
    @app.exception_handler(Exception)
    async def exception_handler(request, exc):
        return JSONResponse(status_code=500, content={'message': 'Internal Server Error'})

Dead Ends

Common approaches that don't work:

  1. 80% fail

    会掩盖真实错误,导致调试困难

  2. 90% fail

    会导致状态不一致,且可能崩溃