4xx Client ErrorCommonly usedRFC 9110
409Conflict
Request conflicts with the current state of the resource.
What it means
The request conflicts with the current state of the target resource. Common when trying to create a duplicate resource (e.g. a user with an email that already exists) or when a version conflict occurs.
When to use it
- ✓Email or username already exists
- ✓Optimistic locking version conflict
- ✓Duplicate unique constraint violation
- ✓Trying to edit a resource being edited by someone else
Common causes
- →Duplicate unique field (email, username, slug)
- →Concurrent edits to the same resource
- →Version mismatch in optimistic locking
Code Examples
Express — duplicate email check
javascript
app.post('/users', async (req, res) => {
const existing = await db.users.findByEmail(req.body.email);
if (existing) {
return res.status(409).json({
error: 'Conflict',
message: 'A user with this email already exists',
});
}
const user = await db.users.create(req.body);
res.status(201).json(user);
});