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:
2026-06-04 14:15:19 +02:00
parent b508273a52
commit df8f31d14d
2 changed files with 110 additions and 15 deletions
+8 -3
View File
@@ -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),
}
}