feat: API3的报错优化

This commit is contained in:
ikechan8370 2023-03-11 11:16:40 +08:00
parent 89d3bb52dd
commit 08fe3314d1
2 changed files with 5 additions and 1 deletions

View file

@ -55,7 +55,7 @@ const defaultConfig = {
noiseScaleW: 0.668,
lengthScale: 1.2,
initiativeChatGroups: [],
version: 'v2.1.3'
version: 'v2.1.4'
}
const _path = process.cwd()
let config = {}

View file

@ -86,6 +86,10 @@ export class OfficialChatGPTClient {
referrer: 'https://chat.openai.com/chat'
}
const res = await this._fetch(url, option)
if (res.status !== 200) {
let body = await res.json()
throw new Error(JSON.stringify(body, null, 2))
}
const decoder = new TextDecoder('utf-8')
const bodyBytes = await res.arrayBuffer()
const bodyText = decoder.decode(bodyBytes)