HTTP 500 Internal Server Error

Quick answer

HTTP 500 Internal Server Error is a generic message that the server hit an unexpected condition and could not complete the request. The request was valid; the failure is on the server.

What HTTP 500 means

500 Internal Server Error is the catch-all server error. The request was fine, but something broke while handling it — most often an unhandled exception in the application code. The response body rarely contains useful detail by design (to avoid leaking internals), so diagnosis happens in the server logs.

Common causes

Example JSON error response

{
  "error": "Internal Server Error",
  "message": "An unexpected error occurred. Please try again later.",
  "status": 500
}

Raw HTTP response

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

How to troubleshoot HTTP 500

500 vs 502 vs 503 — what's the difference?

500 Internal Server Error is a generic failure inside the application handling the request. 502 Bad Gateway means a proxy got an invalid response from an upstream server. 503 Service Unavailable means the server is temporarily overloaded or down for maintenance. 500 points at your app code; 502 and 503 point at infrastructure or upstream services.

Handling a 500 in client code

A 500 is a server-side fault, so a single retry can be reasonable (the error may be transient) — but only with backoff and a cap, and never for non-idempotent operations you can't safely repeat. Surface a friendly message rather than the raw error:

const res = await fetch('/api/report');

if (res.status >= 500) {
  // transient server fault — retry GET with backoff (not POST/PATCH blindly)
  return retryWithBackoff(() => fetch('/api/report'), { max: 3 });
}
if (!res.ok) { /* handle 4xx — do not retry */ }

Don't leak stack traces in the JSON body

A frequent security mistake is returning the raw exception and stack trace in the 500 response body. That exposes file paths, library versions, SQL, and sometimes secrets to anyone who can trigger the error. Return a generic message to the client and keep the real detail in your server logs (with a correlation/request ID the client can quote to support):

{
  "error": "Internal Server Error",
  "message": "Something went wrong. Contact support with this ID.",
  "request_id": "req_8f3c2a",
  "status": 500
}

Frequently Asked Questions

What causes a 500 Internal Server Error?

Almost always an unhandled exception in the server's application code, but it can also be a database failure, a misconfiguration, or a bad deploy. The request itself was valid — the problem is server-side.

How do I debug a 500 error?

Check the server logs for the stack trace, look for unhandled exceptions in the request path, verify database and configuration, and check whether a recent deploy caused it. The client-facing body is intentionally vague, so the logs are where you diagnose.

What is the difference between 500 and 502?

500 is a failure inside the application that handled the request. 502 Bad Gateway means a gateway or proxy received an invalid response from an upstream server it was relaying to. 500 is your app; 502 is the layer in front of (or behind) it.

Should the client retry a 500?

Cautiously. A 500 can be transient, so retrying a safe, idempotent request (like a GET) with exponential backoff and a small retry cap is reasonable. Do not blindly retry non-idempotent operations (POST/PATCH that create or charge) unless they're protected by an idempotency key, or you risk duplicate side effects.

Should a 500 response include the error details?

No — never return the raw stack trace to clients. It can leak file paths, dependency versions, SQL, and secrets. Return a generic message plus a request/correlation ID, and keep the full exception and stack trace in your server logs for diagnosis.

Working with a JSON API response?

Format and inspect any response in your browser — nothing is uploaded.

JSON Formatter JSON Validator All HTTP Status Codes
About the author

Pasindu Ishan is a software developer based in Sri Lanka. He builds privacy-first developer tools at JSON Dev Tools.