500 Internal Server Error
Fault: Server
TL;DR
Generic server error when no specific error code is appropriate.
The server encountered an unexpected condition that prevented it from fulfilling the request.
What This Error Means
The server encountered an unexpected condition that prevented it from fulfilling the request.
Generic server error when no specific error code is appropriate.
Common Causes
- Application crash
- Uncaught exception
- Database connection error
- Code error
- Server misconfiguration
How to Fix It (For Visitors)
- Refresh the page
- Try again later
- Contact website administrator
How to Fix It (For Developers/Admins)
- Check error logs
- Debug application code
- Verify database connectivity
- Check file permissions
- Review recent code changes
- Check PHP/Python/Node.js errors
Code Examples
Here's how to return a 500 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Internal Server Error"}), 500
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(500).json({ message: 'Internal Server Error' });
});
PHP
<?php
http_response_code(500);
header('Content-Type: application/json');
echo json_encode(['message' => 'Internal Server Error']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(500)
json.NewEncoder(w).Encode(map[string]string{
"message": "Internal Server Error",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Internal Server Error");
return ResponseEntity.status(500).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 500
json message: 'Internal Server Error'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.6.1.