remotes/origin/main
Travis Fischer 2023-04-02 11:51:21 -05:00
rodzic c0c2e716ea
commit 07dcc5df31
2 zmienionych plików z 18 dodań i 15 usunięć

Wyświetl plik

@ -218,7 +218,6 @@ export class ChatGPTUnofficialProxyAPI {
} }
} }
} catch (err) { } catch (err) {
// ignore for now; there seem to be some non-json messages
reject(err) reject(err)
} }
}, },

Wyświetl plik

@ -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) => { const feed = (chunk: string) => {
let response = null let response = null
try { try {
response = JSON.parse(chunk) response = JSON.parse(chunk)
} catch { } catch {
/// ignore // ignore
} }
if (response?.detail) {
if (response.detail.type === 'invalid_request_error') { if (response?.detail?.type === 'invalid_request_error') {
const msg = `ChatGPT error ${response.detail.message}: ${response.detail.code} (${response.detail.type})` const msg = `ChatGPT error ${response.detail.message}: ${response.detail.code} (${response.detail.type})`
const error = new types.ChatGPTError(msg, { cause: response }) const error = new types.ChatGPTError(msg, { cause: response })
error.statusCode = response.detail.code error.statusCode = response.detail.code
error.statusText = response.detail.message error.statusText = response.detail.message
if (onError) {
onError(error) if (onError) {
} else { onError(error)
console.error(error) } else {
} console.error(error)
return // don't feed to event parser
} }
// don't feed to the event parser
return
} }
parser.feed(chunk) parser.feed(chunk)
} }