Added error field check

28fc498ee68313cf8d6be0ae8e44a6c6adfd3bc7

bmen25124 <bmen25124@gmail.com>

1 files changed, +6 -6Showing whitespace changes
public/scripts/custom-request.js+6 -6
@@ -86,11 +86,11 @@ export class TextCompletionService {
86 signal: new AbortController().signal,86 signal: new AbortController().signal,
87 });87 });
8888
89 if (!response.ok) {89 const json = await response.json();
90 throw await response.json();90 if (!response.ok || json.error) {
91 throw json;
91 }92 }
9293
93 const json = await response.json();
94 return extractData ? extractMessageFromData(json, this.TYPE) : json;94 return extractData ? extractMessageFromData(json, this.TYPE) : json;
95 }95 }
9696
@@ -156,11 +156,11 @@ export class ChatCompletionService {
156 signal: new AbortController().signal,156 signal: new AbortController().signal,
157 });157 });
158158
159 if (!response.ok) {159 const json = await response.json();
160 throw await response.json();160 if (!response.ok || json.error) {
161 throw json;
161 }162 }
162163
163 const json = await response.json();
164 return extractData ? extractMessageFromData(json, this.TYPE) : json;164 return extractData ? extractMessageFromData(json, this.TYPE) : json;
165 }165 }
166166