Skip to content

500 Internal Server Error — Meaning, Common Causes & How to Fix

500 5xx Server Error RFC 9110 §15.6.1

500 Internal Server Error means: The server hit an unexpected condition that prevented it from fulfilling the request — the generic catch-all for unhandled exceptions, crashes and bugs. It says nothing about the client's request being wrong; the fault is server-side. Server-error 5xx codes mean the server failed while trying to fulfill a valid request. The fault lies with the service or its upstreams, not the caller. Some members are transient and retryable with backoff; others indicate bugs or configuration errors that only the operator can fix. In practice you will meet 500 when an unhandled exception (null reference, type error) in application code; a failed dependency call with no error handling (db down, panic in a library); misconfiguration: missing env vars, bad templates, broken deployments. On the client side, retry once with backoff (transient causes exist), then report the issue with request id/timestamp; the fix belongs to the server operator. On the server side, log the stack trace with a correlation id, return a generic body (never leak internals), alert on 5xx rate, and add handling for the failing path.

Advertisement
Ad slot · ref-top

When 500 happens

  • An unhandled exception (null reference, type error) in application code
  • A failed dependency call with no error handling (DB down, panic in a library)
  • Misconfiguration: missing env vars, bad templates, broken deployments

How to fix it

On the client

Retry once with backoff (transient causes exist), then report the issue with request id/timestamp; the fix belongs to the server operator.

On the server

Log the stack trace with a correlation id, return a generic body (never leak internals), alert on 5xx rate, and add handling for the failing path.

Should you retry?

Retry once or twice with backoff (may be transient); persistent 500s need a server-side fix.

Debugging steps

When 500 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Determine whether the error came from the edge or the origin: a proxy-generated error page looks different from your app's. Then trace upstream health, timeouts and recent deployments. For this code specifically, check whether the most common trigger applies to your situation: an unhandled exception (null reference, type error) in application code. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.

Notes & gotchas

Never leak stack traces or internals in a 500 body: return a generic message plus a correlation id, and keep the real diagnostics in server logs where only operators can see them.

Examples

Raw HTTP
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Content-Length: 126

{
  "error": "internal_server_error",
  "message": "An unhandled exception (null reference, type error) in application code"
}
curl
curl -i https://api.example.com/v1/resource   # observe the 500 response and its headers
JavaScript (fetch)
const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 500) {
  // server-side failure: retry idempotent calls with backoff + jitter,
  // surface a friendly error after the retry budget is exhausted
  throw new TransientError(await res.text());
}
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 500:
    # server fault: back off and retry idempotent calls;
    # log res.headers.get("X-Request-Id") for the operator
    res.raise_for_status()

Frequently asked questions

Should I retry a 500?

Once or twice with backoff is reasonable — some 500s are transient (race conditions, brief dependency blips). Persistent 500s need a server-side fix, not more retries.

Why is the 500 body empty or generic?

Deliberately: detailed errors can leak code paths, queries and secrets. The real diagnostics live in server logs keyed by a correlation id.

Are 5xx errors safe to retry?

Idempotent requests (GET, PUT, DELETE) generally yes, with exponential backoff and jitter. Non-idempotent POSTs need care: a 504 may mean the work completed upstream. Check state or use idempotency keys before retrying.

Who should fix a 5xx — the caller or the provider?

The provider: 5xx asserts a server-side fault. Callers can only retry politely (backoff, idempotency) and report correlation ids; persistent 5xx need operator action on logs, upstreams or configuration.

Advertisement
Ad slot · ref-in-article

Try the JSON Validator

Check JSON syntax and locate errors by line and column.

Open tool →