Repository navigation
fix(api): map feedback and survey constraint violations to 400 instead of 500 - #1110
Merged
Merged
Conversation
mapDBError now maps dberrors.ErrConstraint (and ErrDuplicate/ErrForeignKey, which wrap it) to 400 invalid_input with a fixed message; the raw driver text stays out of the response. 409 is not documented for the feedback POSTs, so StoreErrorToRequestError is not reused. Fixes #1099 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
POST /admin/surveys and PUT /admin/surveys/{id} returned 500 on a
non-duplicate constraint violation (e.g. a status longer than its column
passes the spec's maxLength). Map ErrConstraint to 400 invalid_input after
the duplicate check. Also tidy the mapDBError SEM marker and test setup.
Fixes #1099
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Refs #1099 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015szS68rpMLaq712AFsbMfr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mapDBErrormapsdberrors.ErrConstraint(which wraps duplicate and foreign-key errors) to 400invalid_inputwith a fixed message, so driver text stays out of the response. The detail is logged at Warn.POST /admin/surveysandPUT /admin/surveys/{id}: a constraint violation that isn't a duplicate now returns 400 instead of 500. The PUT case was found by the Fixes (B) sweep.StoreErrorToRequestErrorisn't reused.Test plan
api/feedback_map_db_error_test.gofailed before the fix and passes after itmake verifyFixes #1099
🤖 Generated with Claude Code
https://claude.ai/code/session_015szS68rpMLaq712AFsbMfr