Return 404 (not 500) when adding a term to a non-existent vocabulary #22
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
POST /api/admin/vocabularies/{id}/terms(add_termincrates/api/src/admin_vocab.rs, merged atc4e0c4c) parses{id}as aVocabularyIdand, if the UUID is well-formed but no such vocabulary exists, lets the insert hit a foreign-key violation. That FK error is mapped to 500 Internal Server Error.A well-formed id pointing at a missing vocabulary is a client error, so the correct status is 404 Not Found (consistent with how the object/term/authority endpoints treat missing/unparseable ids elsewhere). Behaviour is safe today — the transaction rolls back — only the status code is coarse.
Task
add_term, pre-check vocabulary existence (e.g.db::vocab::vocabulary_by_key/an existence query, or distinguish the FK violation from othersqlx::Errors) and return404when the vocabulary is absent.500only for genuine DB failures.Acceptance
POST /api/admin/vocabularies/<valid-but-unknown-uuid>/terms→404.201.