kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
remotes/origin/main
rodzic
c0c2e716ea
commit
07dcc5df31
|
@ -218,7 +218,6 @@ export class ChatGPTUnofficialProxyAPI {
|
|||
}
|
||||
}
|
||||
} catch (err) {
|
||||
// ignore for now; there seem to be some non-json messages
|
||||
reject(err)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -36,28 +36,32 @@ export async function fetchSSE(
|
|||
}
|
||||
})
|
||||
|
||||
// check if the response is an error, if so, throw it
|
||||
// handle special response errors
|
||||
const feed = (chunk: string) => {
|
||||
let response = null
|
||||
|
||||
try {
|
||||
response = JSON.parse(chunk)
|
||||
} catch {
|
||||
/// ignore
|
||||
// ignore
|
||||
}
|
||||
if (response?.detail) {
|
||||
if (response.detail.type === 'invalid_request_error') {
|
||||
const msg = `ChatGPT error ${response.detail.message}: ${response.detail.code} (${response.detail.type})`
|
||||
const error = new types.ChatGPTError(msg, { cause: response })
|
||||
error.statusCode = response.detail.code
|
||||
error.statusText = response.detail.message
|
||||
if (onError) {
|
||||
onError(error)
|
||||
} else {
|
||||
console.error(error)
|
||||
}
|
||||
return // don't feed to event parser
|
||||
|
||||
if (response?.detail?.type === 'invalid_request_error') {
|
||||
const msg = `ChatGPT error ${response.detail.message}: ${response.detail.code} (${response.detail.type})`
|
||||
const error = new types.ChatGPTError(msg, { cause: response })
|
||||
error.statusCode = response.detail.code
|
||||
error.statusText = response.detail.message
|
||||
|
||||
if (onError) {
|
||||
onError(error)
|
||||
} else {
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
// don't feed to the event parser
|
||||
return
|
||||
}
|
||||
|
||||
parser.feed(chunk)
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue