From a524a60c463c7c8f151bb7d2e7c5d28662edbef5 Mon Sep 17 00:00:00 2001
From: Yidadaa <yidadaa@qq.com>
Date: Fri, 19 May 2023 00:27:25 +0800
Subject: [PATCH] fix: #1611 show corret message when can not query usage

---
 app/client/platforms/openai.ts | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts
index d833e8c5d..c9197f1e0 100644
--- a/app/client/platforms/openai.ts
+++ b/app/client/platforms/openai.ts
@@ -189,10 +189,14 @@ export class ChatGPTApi implements LLMApi {
       }),
     ]);
 
-    if (!used.ok || !subs.ok || used.status === 401) {
+    if (used.status === 401) {
       throw new Error(Locale.Error.Unauthorized);
     }
 
+    if (!used.ok || !subs.ok) {
+      throw new Error("Failed to query usage from openai");
+    }
+
     const response = (await used.json()) as {
       total_usage?: number;
       error?: {