Go: Fix error code (#16807)

### Summary

As title.

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-07-10 17:02:25 +08:00
committed by GitHub
parent 07a3523b09
commit 2a83ad6cb2
7 changed files with 282 additions and 281 deletions

View File

@@ -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
}