fix(go): redact internal handler errors (#15746)

### What problem does this PR solve?

Refs #15743

Some Go API handlers return raw `err.Error()` strings in
`CodeServerError` responses. Those errors can include internal backend
details such as database, storage, search engine, or host information.

This PR adds a small shared `jsonInternalError` helper for handler-level
internal failures. The helper logs the raw error server-side with
request method/path context, then returns the existing generic
`common.CodeServerError.Message()` to API clients.

This first slice migrates the existing `jsonError(c,
common.CodeServerError, err.Error())` production call sites in agent,
dataset graph, file, and system handlers. It intentionally does not
close the full issue because direct `c.JSON` error responses in other
handlers remain for follow-up PRs.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [ ] New Feature (non-breaking change which adds functionality)
- [ ] Documentation Update
- [ ] Refactoring
- [ ] Performance Improvement
- [ ] Other (please describe):

### Tests

- `/root/go/bin/go test ./internal/handler -count=1`

---------

Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
This commit is contained in:
bitloi
2026-06-12 05:09:10 -03:00
committed by GitHub
parent e96bc37d06
commit 22a058f56c
7 changed files with 86 additions and 19 deletions

View File

@@ -18,12 +18,24 @@ package handler
import (
"net/http"
"ragflow/internal/common"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// jsonInternalError logs the original error while returning a generic message
// to avoid exposing internal implementation details in API responses.
func jsonInternalError(c *gin.Context, err error) {
common.Warn("handler internal error",
zap.Error(err),
zap.String("method", c.Request.Method),
zap.String("path", c.Request.URL.Path),
)
jsonError(c, common.CodeServerError, common.CodeServerError.Message())
}
// HandleNoRoute handles requests to undefined routes
func HandleNoRoute(c *gin.Context) {
// Python parity: GET /api/v1/auth/login/ (an empty OAuth channel) resolves