Skip to main content
Version: 4.x

Internal server error

Type URIhttps://doc.expresso-ts.com/docs/errors/internal-server-error
HTTP status500

The application failed in a way its own code did not expect. The fault is in the application, not in the request.

When it is sent​

A handler or middleware throws an error that is not an AppError and carries no 4xx status, and nothing in the application catches it. The framework answers with 500 and the code EXP2002, and writes the error to the log.

Outside production detail is the error's message:

{
"type": "https://doc.expresso-ts.com/docs/errors/internal-server-error",
"title": "Internal Server Error",
"status": 500,
"detail": "Cannot read properties of undefined (reading 'id')",
"instance": "/api/orders/17",
"errorCode": "EXP2002"
}

In production the message is not sent, because it can describe the inside of the application:

{
"type": "https://doc.expresso-ts.com/docs/errors/internal-server-error",
"title": "Internal Server Error",
"status": 500,
"detail": "An unexpected error occurred.",
"instance": "/api/orders/17",
"errorCode": "EXP2002"
}

What to do​

As the caller: nothing in the request needs to change. As the owner of the application: the log has the error with its stack trace, next to the method and path of the request. For a failure you expect, throw an AppError with the status that fits, so the caller is told what happened.

See Error responses for the shape of the document and how to turn it on.