feat: update i18n messages and improve error handling

This commit is contained in:
JustSong
2025-02-02 16:25:52 +08:00
parent 5659fde3fb
commit 19998ebb8a
6 changed files with 28 additions and 37 deletions

View File

@@ -35,7 +35,7 @@ func Login(c *gin.Context) {
err := json.NewDecoder(c.Request.Body).Decode(&loginRequest)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
"success": false,
})
return
@@ -44,7 +44,7 @@ func Login(c *gin.Context) {
password := loginRequest.Password
if username == "" || password == "" {
c.JSON(http.StatusOK, gin.H{
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
"success": false,
})
return
@@ -131,7 +131,7 @@ func Register(c *gin.Context) {
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
})
return
}
@@ -371,7 +371,7 @@ func UpdateUser(c *gin.Context) {
if err != nil || updatedUser.Id == 0 {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
})
return
}
@@ -435,7 +435,7 @@ func UpdateSelf(c *gin.Context) {
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
})
return
}
@@ -545,7 +545,7 @@ func CreateUser(c *gin.Context) {
if err != nil || user.Username == "" || user.Password == "" {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
})
return
}
@@ -601,7 +601,7 @@ func ManageUser(c *gin.Context) {
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": "无效的参数",
"message": i18n.Translate(c, "invalid_parameter"),
})
return
}