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 {
8686 signal: new AbortController().signal,
8787 });
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;
9192 }
9293
93- const json = await response.json();
9494 return extractData ? extractMessageFromData(json, this.TYPE) : json;
9595 }
9696
@@ -156,11 +156,11 @@ export class ChatCompletionService {
156156 signal: new AbortController().signal,
157157 });
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;
161162 }
162163
163- const json = await response.json();
164164 return extractData ? extractMessageFromData(json, this.TYPE) : json;
165165 }
166166