Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix searchbot return 500, should be 200 with error message (#19763)

Wang Qid5d1fb3de28f
diff --git a/docker/.env b/docker/.env
index 5bb2d7a12d..3897f39f2e 100644
--- a/docker/.env
+++ b/docker/.env
@@ -12,7 +12,7 @@
# running code reports a version older than the database migration marker,
# which any branch targeting a not-yet-tagged release does. Leave it off in
# production, where an older binary must not touch a newer database.
-RAGFLOW_DEV_MODE=false
+# RAGFLOW_DEV_MODE=false
# ------------------------------
# docker env var for specifying vector db type at startup
diff --git a/internal/handler/searchbot.go b/internal/handler/searchbot.go
index 39a3a95cd7..6ee5b10221 100644
--- a/internal/handler/searchbot.go
+++ b/internal/handler/searchbot.go
@@ -210,7 +210,7 @@ func (h *SearchBotHandler) RetrievalTest(c *gin.Context) {
result, err := h.chunkSvc.RetrievalTest(ctx, svcReq, user.ID)
if err != nil {
common.Warn("search bot retrieval test failed", zap.String("error", err.Error()))
- common.ResponseWithHttpCodeData(c, http.StatusInternalServerError, common.CodeServerError, nil, "retrieval test failed")
+ common.ResponseWithCodeData(c, common.CodeDataError, nil, err.Error())
return
}
diff --git a/internal/handler/searchbot_test.go b/internal/handler/searchbot_test.go
index fe0002dcce..0d01b56bf8 100644
--- a/internal/handler/searchbot_test.go
+++ b/internal/handler/searchbot_test.go
@@ -176,20 +176,18 @@ func TestSearchBotsRetrieval_ServiceError(t *testing.T) {
req, _ := http.NewRequest("POST", "/api/v1/searchbots/retrieval_test", strings.NewReader(body))
req.Header.Set("Content-Type", "application/json")
r.ServeHTTP(w, req)
- if w.Code != http.StatusInternalServerError {
- t.Errorf("expected 500, got %d", w.Code)
+ if w.Code != http.StatusOK {
+ t.Errorf("expected 200, got %d", w.Code)
}
var resp map[string]interface{}
if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
t.Fatalf("failed to unmarshal response: %v", err)
}
- code, _ := resp["code"].(float64)
- if code == 0 {
- t.Errorf("expected non-zero error code, got %v", code)
+ if resp["code"] != float64(common.CodeDataError) {
+ t.Errorf("expected code %d, got %v", common.CodeDataError, resp["code"])
}
- msg, _ := resp["message"].(string)
- if msg == "" || msg == "success" {
- t.Errorf("expected error message, got %q", msg)
+ if resp["message"] != "db error" {
+ t.Errorf("expected message %q, got %v", "db error", resp["message"])
}
}