500 500 Internal Server Error
The server encountered an unexpected condition that prevented it from fulfilling the request.
What Is This?
The HTTP 500 Internal Server Error status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. It is a generic catch-all error for server-side failures. Unlike 4xx errors (client mistakes), 500 means the server failed to handle a valid request. The error could be caused by uncaught exceptions, database failures, configuration errors, or any other server-side issue.
Common Causes & Solutions
Common Cause
Uncaught exceptions or runtime errors in application code
Common Cause
Database connection failures or query timeouts
Common Cause
Misconfigured server settings or missing environment variables
Common Cause
File system permission errors or disk space exhaustion
Check server logs
Always start debugging 500 errors by checking application and server logs. The logs will contain the specific error message and stack trace.
# View live logs journalctl -u myapp -f # Node.js — check stderr pm2 logs myapp # Check Nginx error log tail -f /var/log/nginx/error.log # Docker docker logs mycontainer --tail 100
Implement error boundaries and logging
Use global error handlers to catch uncaught exceptions and log them with context.
// Node.js (Express) global error handler
app.use((err, req, res, next) => {
console.error('Unhandled error:', {
message: err.message,
stack: err.stack,
url: req.originalUrl,
method: req.method,
timestamp: new Date().toISOString()
})
res.status(500).json({
error: 'Internal Server Error',
message: process.env.NODE_ENV === 'production'
? 'Something went wrong'
: err.message
})
})Related Entries
More from this reference:
502 502 Bad Gateway
The server acting as a gateway received an invalid response from an upstream server.
503 503 Service Unavailable
The server is temporarily unable to handle the request, typically due to maintenance or overload.
504 504 Gateway Timeout
The server acting as a gateway did not receive a timely response from an upstream server.
Frequently Asked Questions
Should I expose error details in 500 responses?
In production, never expose stack traces or internal details in 500 responses — they can leak sensitive information. Log the details server-side and return a generic error message. In development, showing details helps debugging.
What is the difference between 500 and 502?
500 is a generic server error on the server you are directly connecting to. 502 Bad Gateway means the server was acting as a gateway or proxy and received an invalid response from an upstream server. 500 is 'my server broke', 502 is 'the server I called broke'.