Просмотр исходного кода

fix: fix the wrong message when channel is deleted

JustSong 2 лет назад
Родитель
Сommit
aabc546691
3 измененных файлов с 10 добавлено и 2 удалено
  1. 3 1
      i18n/en.json
  2. 6 1
      middleware/distributor.go
  3. 1 0
      model/ability.go

+ 3 - 1
i18n/en.json

@@ -456,5 +456,7 @@
   "提示": "Prompt",
   "补全": "Completion",
   "消耗额度": "Used Quota",
-  "可选值": "Optional Values"
+  "可选值": "Optional Values",
+  "渠道不存在:%d": "Channel does not exist: %d",
+  "数据库一致性已被破坏,请联系管理员": "Database consistency has been broken, please contact the administrator"
 }

+ 6 - 1
middleware/distributor.go

@@ -75,9 +75,14 @@ func Distribute() func(c *gin.Context) {
 			}
 			channel, err = model.CacheGetRandomSatisfiedChannel(userGroup, modelRequest.Model)
 			if err != nil {
+				message := "无可用渠道"
+				if channel != nil {
+					common.SysError(fmt.Sprintf("渠道不存在:%d", channel.Id))
+					message = "数据库一致性已被破坏,请联系管理员"
+				}
 				c.JSON(http.StatusServiceUnavailable, gin.H{
 					"error": gin.H{
-						"message": "无可用渠道",
+						"message": message,
 						"type":    "one_api_error",
 					},
 				})

+ 1 - 0
model/ability.go

@@ -24,6 +24,7 @@ func GetRandomSatisfiedChannel(group string, model string) (*Channel, error) {
 		return nil, err
 	}
 	channel := Channel{}
+	channel.Id = ability.ChannelId
 	err = DB.First(&channel, "id = ?", ability.ChannelId).Error
 	return &channel, err
 }