liveBook · Manning

500 Internal Server Error

As explained in The Design of Web APIs, Second Edition

500 Internal Server Error is an HTTP status code indicating that the server encountered an unexpected condition that prevented it from fulfilling the request.

500 Internal Server Error is the HTTP status for an unexpected failure on the provider’s side. Every API operation needs this error output: even a valid request can fail because of an implementation problem or unavailable infrastructure. section 4.5.9 section 4.9

Choose the status according to what went wrong:

  • Use 400 Bad Request for missing or invalid input, not for an unexpected server failure. section 4.5.10
  • Use 404 Not Found when a resource identified by a path parameter cannot be found. section 4.5.10
  • Include 500 Internal Server Error among the documented outputs of every operation. section 4.5.9

An error without a disclosure

Suppose a database connection fails. A 500 response should not expose a database error code, server IP address, or database engine. Return a generic message instead. If investigation needs a reference, a Problem Details response can include an opaque `instance` URI such as `/unexpected-errors/12345`; the reference can also appear in the message shown to the consumer. section 12.10.3

When documenting an operation in OpenAPI, check that its 500 response is present and that its message reveals no sensitive implementation details. A reference can help investigate the occurrence without exposing the underlying failure. section 12.10 section 12.10.3

How The Design of Web APIs, Second Edition covers it

How deep it goes
Defines when to select 500 and how to write a safer response, but does not develop server-side recovery procedures.
Examples
Uses null-value access and infrastructure failures as causes, plus a database-connection message that exposes an IP address as a response to avoid.
What it assumes
Assumes familiarity with HTTP status selection and user-friendly errors while introducing how to complete unexpected-error documentation in OpenAPI.
What you can do after
Operate/configure it by documenting 500 on every operation and returning generic error information with an optional investigation reference.
How it connects
Distinguishes 500 from 400 Bad Request and 404 Not Found, then connects its response to OpenAPI and Problem Details for HTTP APIs.

Also explained in

Compare how 2 books explain 500 Internal Server Error →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.