Merge pull request #3609 from bmen25124/error_field_check_custom_request Added error field check
Signed| @@ -86,11 +86,11 @@ export class TextCompletionService { | ||
| 86 | 86 | signal: new AbortController().signal, |
| 87 | 87 | }); |
| 88 | 88 | |
| 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 | } |
| 92 | 93 | |
| 93 | - const json = await response.json(); | |
| 94 | 94 | return extractData ? extractMessageFromData(json, this.TYPE) : json; |
| 95 | 95 | } |
| 96 | 96 | |
| @@ -156,11 +156,11 @@ export class ChatCompletionService { | ||
| 156 | 156 | signal: new AbortController().signal, |
| 157 | 157 | }); |
| 158 | 158 | |
| 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 | } |
| 162 | 163 | |
| 163 | - const json = await response.json(); | |
| 164 | 164 | return extractData ? extractMessageFromData(json, this.TYPE) : json; |
| 165 | 165 | } |
| 166 | 166 | |