api: return 400 instead of 500 on duplicate changefeed creation#5428
api: return 400 instead of 500 on duplicate changefeed creation#5428rajneesh2k10 wants to merge 1 commit into
Conversation
ErrChangeFeedAlreadyExists was not in the httpBadRequestError registry, so the v2 CreateChangefeed handler returned HTTP 500 when a client posted a changefeed ID that already existed. A duplicate-create is a client-side condition and should be a 4xx. Adds the error to the existing bad-request registry, mirroring how ErrChangeFeedNotExists is already classified, and adds a TestErrorHandleMiddleware regression test. close pingcap#5427
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @rajneesh2k10. Thanks for your PR. I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Welcome @rajneesh2k10! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesErrChangeFeedAlreadyExists HTTP 400 fix and test
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request adds cerror.ErrChangeFeedAlreadyExists to the list of errors mapped to an HTTP 400 Bad Request status in pkg/api/util.go. It also introduces a new unit test TestErrorHandleMiddleware in api/middleware/middleware_test.go to verify the error handling middleware's behavior under different scenarios. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
[FORMAT CHECKER NOTIFICATION] Notice: To remove the 📖 For more info, you can check the "Contribute Code" section in the development guide. |
ErrChangeFeedAlreadyExists was not in the httpBadRequestError registry, so the v2 CreateChangefeed handler returned HTTP 500 when a client posted a changefeed ID that already existed. A duplicate-create is a client-side condition and should be a 4xx.
Adds the error to the existing bad-request registry, mirroring how ErrChangeFeedNotExists is already classified, and adds a TestErrorHandleMiddleware regression test.
close #5427
What problem does this PR solve?
Issue Number: close #5427
The v2
POST /api/v2/changefeedsendpoint returned HTTP 500 when the requested changefeed ID already existed, becauseErrChangeFeedAlreadyExistswas not registered in the middleware's bad-request error list. Clients could not distinguishthis duplicate condition from a real server fault.
What is changed and how it works?
pkg/api/util.go: addErrChangeFeedAlreadyExiststohttpBadRequestError, grouped next toErrChangeFeedNotExists. Theexisting
IsHTTPBadRequestErrormatcher already handles direct equality, RFC code, and wrapped errors, so no other plumbingis needed.
api/middleware/middleware_test.go: addTestErrorHandleMiddlewarepinning the 200 / 400 / 500 buckets, including theduplicate-changefeed → 400 case as a regression guard.
Check List
Tests
Questions
Will it cause performance regression or break compatibility?
Changes the HTTP response code for one error case from 500 to 400. Clients that previously treated the 500 as a transient
server fault and retried will now see a 4xx and (correctly) stop retrying. No wire-format or API-shape changes.
Do you need to update user documentation, design documentation or monitoring documentation?
No.
Release note
Summary by CodeRabbit