5xx Server ErrorCommonly usedRFC 9110
500Internal Server Error
Server encountered an unexpected error.
What it means
A generic error meaning something went wrong on the server. It is a catch-all for server-side errors. The server encountered an unexpected condition that prevented it from fulfilling the request. Never expose internal error details to clients in production.
When to use it
- ✓Unhandled exception in server code
- ✓Database connection failed
- ✓Third-party service call failed unexpectedly
- ✓Bug in application code
Common causes
- →Unhandled promise rejection
- →Null pointer / undefined access
- →Database query error
- →Out of memory
Code Examples
Express — global error handler
javascript
// Always add this last in Express
app.use((err, req, res, next) => {
// Log internally — never expose to client
console.error(err.stack);
res.status(500).json({
error: 'Internal Server Error',
message: 'Something went wrong. Please try again.',
// Never: message: err.message in production
});
});
// Catch async errors
app.get('/data', async (req, res, next) => {
try {
const data = await fetchData();
res.json(data);
} catch (err) {
next(err); // passes to error handler above
}
});Quick Facts
Code500
CategoryServer Error
SpecRFC 9110
CommonYes