Repository navigation
Go: Update response message - #16803
Conversation
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
|
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)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR changes response helpers and handler call sites to use typed ChangesResponse-code migration
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (1 warning, 2 inconclusive)
✅ Passed checks (2 passed)
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 |
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/admin/enterprise_handler.go (1)
1530-1536: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winMissing
returnafter error response inListUsersQuota.Line 1534 sends an error response when
topparsing fails but does not return. Execution continues toh.service.ListUsersQuotaand potentiallycommon.SuccessWithData, writing a second response body. This corrupts the HTTP response for any request with an invalidtopparameter.🐛 Proposed fix: add missing return
if topStr != "" { top, err = strconv.Atoi(topStr) if err != nil { common.ErrorWithCode(c, 400, "Top must be an integer") + return } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/admin/enterprise_handler.go` around lines 1530 - 1536, In ListUsersQuota, return immediately after common.ErrorWithCode reports an invalid top parameter; add the missing return inside the strconv.Atoi error branch so execution does not continue to the service call or success response.
🧹 Nitpick comments (1)
internal/admin/enterprise_handler.go (1)
543-543: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReplace remaining raw integer literals with typed
ErrorCodeconstants for consistency.Several functions in this file were partially migrated —
CodeBadRequest/CodeNotFound/CodeUnauthorizedcalls now use typed constants, but500/404/400raw integers remain in the same functions. SinceErrorWithCodenow acceptsErrorCode, replace these withcommon.CodeServerError,common.CodeNotFound,common.CodeBadRequestrespectively to complete the migration.♻️ Example fixes (apply similarly throughout the file)
- common.ErrorWithCode(c, 500, err.Error()) + common.ErrorWithCode(c, common.CodeServerError, err.Error())- common.ErrorWithCode(c, 404, "User not found") + common.ErrorWithCode(c, common.CodeNotFound, "User not found")- common.ErrorWithCode(c, 400, err.Error()) + common.ErrorWithCode(c, common.CodeBadRequest, err.Error())Also applies to: 599-599, 667-667, 735-735, 768-768, 808-808, 830-830, 833-833, 856-856, 860-860, 867-867, 870-870, 1305-1305, 1308-1308, 1336-1336, 1345-1345, 1353-1353, 1356-1356, 1516-1516, 1525-1525, 1534-1534, 1541-1541, 1544-1544, 1671-1671, 1674-1674, 1696-1696, 1700-1700, 1707-1707, 1710-1710, 1736-1736, 1739-1739
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/admin/enterprise_handler.go` at line 543, Replace every remaining raw 500, 404, and 400 argument passed to ErrorWithCode throughout the affected handlers with common.CodeServerError, common.CodeNotFound, and common.CodeBadRequest respectively, including the calls near the listed locations. Preserve each existing error message and ensure all ErrorWithCode calls use typed ErrorCode constants consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/handler/providers.go`:
- Line 610: In AddModel, replace the success-path call to common.ErrorWithCode
with common.SuccessWithMessage, preserving the existing response code and
"success" message so the response includes the expected data field.
---
Outside diff comments:
In `@internal/admin/enterprise_handler.go`:
- Around line 1530-1536: In ListUsersQuota, return immediately after
common.ErrorWithCode reports an invalid top parameter; add the missing return
inside the strconv.Atoi error branch so execution does not continue to the
service call or success response.
---
Nitpick comments:
In `@internal/admin/enterprise_handler.go`:
- Line 543: Replace every remaining raw 500, 404, and 400 argument passed to
ErrorWithCode throughout the affected handlers with common.CodeServerError,
common.CodeNotFound, and common.CodeBadRequest respectively, including the calls
near the listed locations. Preserve each existing error message and ensure all
ErrorWithCode calls use typed ErrorCode constants consistently.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b5778837-fd20-434f-ab54-aaa5c7c7e7f1
📒 Files selected for processing (35)
cmd/ragflow_server.gointernal/admin/enterprise_handler.gointernal/admin/handler.gointernal/common/response.gointernal/handler/agent.gointernal/handler/agent_component.gointernal/handler/agent_test.gointernal/handler/agent_upload.gointernal/handler/agent_wait_for_user_test.gointernal/handler/bot.gointernal/handler/chat.gointernal/handler/chat_channel.gointernal/handler/chat_recommendation.gointernal/handler/chat_session.gointernal/handler/chunk.gointernal/handler/connector.gointernal/handler/dataset.gointernal/handler/document.gointernal/handler/file.gointernal/handler/file_commit.gointernal/handler/langfuse.gointernal/handler/llm.gointernal/handler/mcp.gointernal/handler/mcp_server.gointernal/handler/memory.gointernal/handler/plugin.gointernal/handler/providers.gointernal/handler/search.gointernal/handler/searchbot.gointernal/handler/skill_search.gointernal/handler/stats.gointernal/handler/system.gointernal/handler/tenant.gointernal/handler/user.gointernal/router/router.go
| } | ||
|
|
||
| common.ErrorWithCode(c, int(code), "success") | ||
| common.ErrorWithCode(c, code, "success") |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use SuccessWithMessage instead of ErrorWithCode for the success response in AddModel.
AddModel sends its success message through the error response helper, which omits the data field from the JSON envelope ({"code":0,"message":"success"}). Every other handler in this file uses SuccessWithMessage for no-data success responses, producing {"code":0,"data":null,"message":"success"}. This contract inconsistency can break clients that expect the data key.
🐛 Proposed fix
- common.ErrorWithCode(c, code, "success")
+ common.SuccessWithMessage(c, "success")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| common.ErrorWithCode(c, code, "success") | |
| common.SuccessWithMessage(c, "success") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/handler/providers.go` at line 610, In AddModel, replace the
success-path call to common.ErrorWithCode with common.SuccessWithMessage,
preserving the existing response code and "success" message so the response
includes the expected data field.
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Summary
As title.