浏览代码

fix(api): 优化错误处理逻辑

- 当错误代码不存在于 errorCodeMap 时,使用 data 中的字符串作为错误信息
- 提高了错误处理的灵活性和可读性
fusu 3 月之前
父节点
当前提交
573dd78d7d
共有 1 个文件被更改,包括 1 次插入1 次删除
  1. 1 1
      api/v1/v1.go

+ 1 - 1
api/v1/v1.go

@@ -29,7 +29,7 @@ func HandleError(ctx *gin.Context, httpCode int, err error, data interface{}) {
 	}
 	resp := Response{Code: errorCodeMap[err], Message: err.Error(), Data: data}
 	if _, ok := errorCodeMap[err]; !ok {
-		resp = Response{Code: 500, Message: "unknown error", Data: data}
+		resp = Response{Code: 500, Message: data.(string)}
 	}
 	ctx.JSON(httpCode, resp)
 }