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

fix: do not consume user quota if failed

CaIon 2 лет назад
Родитель
Сommit
3432d9e0f6
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      controller/relay-image.go

+ 3 - 0
controller/relay-image.go

@@ -170,6 +170,9 @@ func relayImageHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
 	var textResponse ImageResponse
 	var textResponse ImageResponse
 	defer func(ctx context.Context) {
 	defer func(ctx context.Context) {
 		if consumeQuota {
 		if consumeQuota {
+			if resp.StatusCode != http.StatusOK {
+				return
+			}
 			err := model.PostConsumeTokenQuota(tokenId, userQuota, quota, 0, true)
 			err := model.PostConsumeTokenQuota(tokenId, userQuota, quota, 0, true)
 			if err != nil {
 			if err != nil {
 				common.SysError("error consuming token remain quota: " + err.Error())
 				common.SysError("error consuming token remain quota: " + err.Error())