500 Internal Server Error

The application code threw and nothing caught it: an unhandled exception, a null dereference, a failed assertion. Of the common 5xx family, 500 is the one that is unambiguously your bug — the stack trace is in your application logs, at the timestamp of the request.

What usually causes it

  • Unhandled exceptions on edge-case inputs
  • Failed dependencies without graceful handling (DB down → exception → 500)
  • Bad deployments (missing env vars, broken migrations)

How to debug and fix it

  1. Get the request ID / timestamp and go straight to app logs or your error tracker (Sentry-class tooling exists exactly for this).
  2. If 500s started at a deploy, roll back first and diagnose second.
  3. Never leak stack traces in the response body in production — log them, return a reference ID.
  4. Convert 'expected' failures (bad input, missing resource) into their correct 4xx codes so real 500s stay meaningful.

Easily confused with