500 Internal Server Error는 서버가 요청을 처리하다가 예상치 못한 상황을 만나 실패했음을 알리는 포괄적(catch-all) 오류입니다. 클라이언트 요청 자체는 문제가 없을 수 있으며, 원인은 서버 코드나 그 의존성 쪽에 있습니다.
이 코드는 구체적인 원인을 알려주지 않습니다. 실제 원인(예외, 스택 트레이스, 실패한 쿼리)은 서버 로그에 있으므로, 500을 만나면 가장 먼저 서버 로그와 요청 ID를 확인해야 합니다.
GET /api/orders/42 HTTP/1.1
Host: api.example.com
Accept: application/jsonHTTP/1.1 500 Internal Server Error
Content-Type: application/json
{"error":"internal_error","requestId":"a1b2c3d4"}// Central error middleware: log the detail, return a generic 500
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).json({ error: 'internal_error', requestId: req.id });
});@app.errorhandler(Exception)
def handle(err):
app.logger.exception(err)
return jsonify(error='internal_error'), 500