diff --git a/i18n/en.json b/i18n/en.json index 68b124ec..3c94b0e3 100644 --- a/i18n/en.json +++ b/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" } diff --git a/middleware/distributor.go b/middleware/distributor.go index 9da2ed1e..314677c7 100644 --- a/middleware/distributor.go +++ b/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", }, }) diff --git a/model/ability.go b/model/ability.go index 1b33916c..e87c3940 100644 --- a/model/ability.go +++ b/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 }