500 Error
An HTTP status code indicating an internal server error, meaning the server encountered an unexpected condition that prevented it from fulfilling the request.
Overview
500 Internal Server Error is a generic error message indicating that something went wrong on the server side. Unlike 4xx errors which indicate client-side issues, 5xx errors mean the problem is with the server. This could be due to bugs in server code, database connection issues, or misconfiguration.
Example
javascript// Handling 500 errors in fetch fetch('https://api.example.com/users') .then(response => { if (response.status === 500) { throw new Error('Server error occurred'); } if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response.json(); }) .catch(error => { console.error('Error:', error); // Show user-friendly error message }); // Axios interceptor for 500 errors axios.interceptors.response.use( response => response, error => { if (error.response?.status === 500) { console.error('Server error:', error); // Show error notification to user } return Promise.reject(error); } ); // Express.js error handling app.get('/api/data', async (req, res, next) => { try { const data = await fetchData(); res.json(data); } catch (error) { console.error(error); res.status(500).json({ error: 'Internal Server Error' }); } });
Common Causes
- Server code throwing unhandled exceptions
- Database connection failures
- File system permission issues
- Server resource exhaustion
- Misconfigured server settings
Key Points
- Indicates server-side error
- Generic error message (security best practice)
- Should be logged on server for debugging
- Show user-friendly message to users
- Part of 5xx server error status codes
Learn More
- 200 OK - Success status
- 404 Error - Not found error
- Fetch - Fetch API
- MDN: HTTP Status 500