409

Conflict

개요

409 Conflict는 요청이 리소스의 현재 상태와 충돌하여 처리할 수 없음을 나타냅니다. 요청 자체는 형식적으로 유효하지만, 서버의 현재 상태와 양립할 수 없는 변경을 시도할 때 반환됩니다.

대표적으로 두 사용자가 같은 문서를 동시에 수정하다 발생하는 편집 충돌(lost update), 이미 존재하는 값으로 인한 유일성 제약 위반, 버전 불일치가 있습니다.

언제 발생하나

요청 / 응답 예시

요청
PUT /api/docs/7 HTTP/1.1
Host: api.example.com
If-Match: "v3"
Content-Type: application/json

{"title":"Edited"}
응답
HTTP/1.1 409 Conflict
Content-Type: application/json

{"error":"conflict","message":"Document was modified by another user","currentVersion":"v5"}

코드로 보기

app.put('/api/docs/:id', (req, res) => {
  const doc = db.get(req.params.id);
  if (req.headers['if-match'] !== doc.etag)
    return res.status(409).json({ error: 'conflict', currentVersion: doc.etag });
  // ...
});
@app.post('/api/users')
def create():
    if db.exists(email=request.json['email']):
        abort(409, 'email already registered')
    return {}, 201

흔한 원인

해결 방법

실무 참고

관련 상태코드

관련 헤더

스펙 근거