500

Internal Server Error

개요

500 Internal Server Error는 서버가 요청을 처리하다가 예상치 못한 상황을 만나 실패했음을 알리는 포괄적(catch-all) 오류입니다. 클라이언트 요청 자체는 문제가 없을 수 있으며, 원인은 서버 코드나 그 의존성 쪽에 있습니다.

이 코드는 구체적인 원인을 알려주지 않습니다. 실제 원인(예외, 스택 트레이스, 실패한 쿼리)은 서버 로그에 있으므로, 500을 만나면 가장 먼저 서버 로그와 요청 ID를 확인해야 합니다.

언제 발생하나

요청 / 응답 예시

요청
GET /api/orders/42 HTTP/1.1
Host: api.example.com
Accept: application/json
응답
HTTP/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

흔한 원인

해결 방법

실무 참고

관련 상태코드

관련 헤더

스펙 근거