mirror of
https://github.com/morgan9e/chatgpt-web
synced 2026-04-14 00:14:04 +09:00
Handle some more API errors
This commit is contained in:
@@ -11,9 +11,7 @@
|
||||
getMessage,
|
||||
currentChatMessages,
|
||||
setCurrentChat,
|
||||
|
||||
currentChatId
|
||||
|
||||
} from './Storage.svelte'
|
||||
import {
|
||||
type Message,
|
||||
|
||||
@@ -90,7 +90,10 @@ export class ChatCompletionResponse {
|
||||
|
||||
updateFromSyncResponse (response: Response) {
|
||||
this.setModel(response.model)
|
||||
response.choices.forEach((choice, i) => {
|
||||
if (!response.choices) {
|
||||
return this.updateFromError(response?.error?.message || 'unexpected response from API')
|
||||
}
|
||||
response.choices?.forEach((choice, i) => {
|
||||
const exitingMessage = this.messages[i]
|
||||
const message = exitingMessage || choice.message
|
||||
if (exitingMessage) {
|
||||
@@ -121,7 +124,10 @@ export class ChatCompletionResponse {
|
||||
updateFromAsyncResponse (response: Response) {
|
||||
let completionTokenCount = 0
|
||||
this.setModel(response.model)
|
||||
response.choices.forEach((choice, i) => {
|
||||
if (!response.choices) {
|
||||
return this.updateFromError(response?.error?.message || 'unexpected streaming response from API')
|
||||
}
|
||||
response.choices?.forEach((choice, i) => {
|
||||
const message = this.messages[i] || {
|
||||
role: 'assistant',
|
||||
content: '',
|
||||
|
||||
@@ -451,7 +451,7 @@ export class ChatRequest {
|
||||
...overrides
|
||||
} as ChatSettings)
|
||||
// Wait for the response to complete
|
||||
if (!summary.hasFinished()) await summary.promiseToFinish()
|
||||
if (!summary.hasError() && !summary.hasFinished()) await summary.promiseToFinish()
|
||||
if (summary.hasError()) {
|
||||
// Failed for some API issue. let the original caller handle it.
|
||||
_this.updating = false
|
||||
|
||||
Reference in New Issue
Block a user