{
  "id": "python/starlette-httperror-internal-server-error",
  "signature": "HTTPException: 500 Internal Server Error",
  "signature_zh": "HTTPException: 500 内部服务器错误",
  "regex": "HTTPException:\\ 500\\ Internal\\ Server\\ Error",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "An unhandled exception occurred in the application code.",
  "root_cause_type": "generic",
  "root_cause_zh": "应用程序代码中发生了未处理的异常。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a bare except clause that hides the error.",
      "why_fails": "Bare except catches all exceptions but doesn't log them, making debugging hard.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "Returning a string without proper error handling.",
      "why_fails": "Returning a string doesn't prevent the 500 error; it only changes the response body.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add exception handlers to log and return custom responses.",
      "success_rate": 0.9,
      "how": "from starlette.responses import JSONResponse\n@app.exception_handler(500)\nasync def internal_error(request, exc):\n    return JSONResponse({'error': 'Internal server error'}, status_code=500)",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use middleware to catch unhandled exceptions.",
      "success_rate": 0.85,
      "how": "from starlette.middleware.base import BaseHTTPMiddleware\nclass ErrorHandlerMiddleware(BaseHTTPMiddleware):\n    async def dispatch(self, request, call_next):\n        try:\n            response = await call_next(request)\n        except Exception as e:\n            return JSONResponse({'error': str(e)}, status_code=500)\n        return response",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-06-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}