Merge pull request #3609 from bmen25124/error_field_check_custom_request Added error field check

70f762c006151886c978069430703768ee0d8a0d

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +6 -6Ignore whitespace
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