500

Internal Server Error

5xx · Server Error common

Overview

500 Internal Server Error is a generic catch-all telling the client the server hit an unexpected condition and failed while handling the request. The client's request may be perfectly valid; the fault lies in the server code or its dependencies.

This code does not reveal the specific cause. The real reason (an exception, a stack trace, a failed query) lives in the server logs, so the first move on a 500 is to check the server logs and the request ID.

When it happens

Request / Response example

Request
GET /api/orders/42 HTTP/1.1
Host: api.example.com
Accept: application/json
Response
HTTP/1.1 500 Internal Server Error
Content-Type: application/json

{"error":"internal_error","requestId":"a1b2c3d4"}

In code

// Central error middleware: log the detail, return a generic 500
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).json({ error: 'internal_error', requestId: req.id });
});
@app.errorhandler(Exception)
def handle(err):
    app.logger.exception(err)
    return jsonify(error='internal_error'), 500

Common causes

How to fix

Notes

Related status codes

Related headers

Specification