mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-11 22:25:41 +08:00
Go: Fix error code (#16807)
### Summary As title. --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -122,18 +122,18 @@ func (h *ChatSessionHandler) ChatCompletions(c *gin.Context) {
|
||||
|
||||
var rawBody map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&rawBody); err != nil {
|
||||
common.ErrorWithCode(c, 400, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var req ChatCompletionsRequest
|
||||
b, err := json.Marshal(rawBody)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, 400, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(b, &req); err != nil {
|
||||
common.ErrorWithCode(c, 400, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1476,7 +1476,7 @@ func (h *DocumentHandler) RemoveIngestionTasks(c *gin.Context) {
|
||||
}
|
||||
|
||||
if req.Tasks == nil || len(req.Tasks) == 0 {
|
||||
common.ErrorWithCode(c, 1, "task_ids is required")
|
||||
common.ErrorWithCode(c, common.CodeLackResources, "task_ids is required")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -66,17 +66,17 @@ func (h *ModelHandler) ListAllModels(c *gin.Context) {
|
||||
func (h *ModelHandler) ShowModel(c *gin.Context) {
|
||||
encodedModelName := c.Param("model_name")
|
||||
if encodedModelName == "" {
|
||||
common.ErrorWithCode(c, 400, "Encoded model name is empty")
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Encoded model name is empty")
|
||||
return
|
||||
}
|
||||
|
||||
decodedModelName, err := common.DecodeFromBase64(encodedModelName)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, 400, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if decodedModelName == "" {
|
||||
common.ErrorWithCode(c, 400, "Decoded model name is empty")
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Decoded model name is empty")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ func (h *SystemHandler) SetLogLevel(c *gin.Context) {
|
||||
func (h *SystemHandler) ListVariables(c *gin.Context) {
|
||||
variables, err := h.systemService.ListAllVariables()
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, 500, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -206,22 +206,22 @@ type SetVariableHTTPRequest struct {
|
||||
func (h *SystemHandler) SetVariable(c *gin.Context) {
|
||||
var req SetVariableHTTPRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.ErrorWithCode(c, 400, "Var name is required")
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Var name is required")
|
||||
return
|
||||
}
|
||||
|
||||
if req.VarName == "" {
|
||||
common.ErrorWithCode(c, 400, "Var name is required")
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Var name is required")
|
||||
return
|
||||
}
|
||||
|
||||
if req.VarValue == "" {
|
||||
common.ErrorWithCode(c, 400, "Var value is required")
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Var value is required")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.systemService.SetVariable(req.VarName, req.VarValue); err != nil {
|
||||
common.ErrorWithCode(c, 500, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -233,17 +233,17 @@ func (h *SystemHandler) ShowVariable(c *gin.Context) {
|
||||
|
||||
varName, err := common.DecodeFromBase64(encodedVarName)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, 400, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if varName == "" {
|
||||
common.ErrorWithCode(c, 400, "Var name is required")
|
||||
common.ErrorWithCode(c, common.CodeBadRequest, "Var name is required")
|
||||
return
|
||||
}
|
||||
|
||||
variable, err := h.systemService.ShowVariable(varName)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, 500, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ func (h *SystemHandler) ShowVariable(c *gin.Context) {
|
||||
func (h *SystemHandler) ListEnvironments(c *gin.Context) {
|
||||
environments, err := h.systemService.ListEnvironments()
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, 500, err.Error())
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user