fix(api): map nonexistent-vocabulary FK violation to 422; cover term/authority create paths
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -494,10 +494,15 @@ pub(crate) async fn create_field_definition(
|
||||
|
||||
Ok((StatusCode::CREATED, Json(CreatedField { key: new.key })))
|
||||
}
|
||||
Err(err) if err.as_database_error().and_then(|e| e.code()).as_deref() == Some("23505") => {
|
||||
Err(StatusCode::CONFLICT)
|
||||
Err(err) => {
|
||||
match err.as_database_error().and_then(|e| e.code()).as_deref() {
|
||||
// Duplicate `key` violates the unique index.
|
||||
Some("23505") => Err(StatusCode::CONFLICT),
|
||||
// Referenced vocabulary doesn't exist — client error, not server fault.
|
||||
Some("23503") => Err(StatusCode::UNPROCESSABLE_ENTITY),
|
||||
_ => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
}
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user