mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 增加错误输出
This commit is contained in:
parent
c36a0f9c9c
commit
7c5e9ea434
1 changed files with 29 additions and 23 deletions
|
|
@ -156,31 +156,37 @@ export class ClaudeAIClient {
|
|||
if (streamDataRes.status === 307) {
|
||||
throw new Error('claude.ai目前不支持你所在的地区')
|
||||
}
|
||||
let streamData = streamDataRes.body
|
||||
// console.log(streamData)
|
||||
let responseText = ''
|
||||
let streams = streamData.split('\n\n')
|
||||
for (let s of streams) {
|
||||
let jsonStr = s.replace('data: ', '').trim()
|
||||
try {
|
||||
let jsonObj = JSON.parse(jsonStr)
|
||||
if (jsonObj && jsonObj.completion) {
|
||||
responseText += jsonObj.completion
|
||||
}
|
||||
if (this.debug) {
|
||||
console.log(jsonObj)
|
||||
}
|
||||
// console.log(responseText)
|
||||
} catch (err) {
|
||||
// ignore error
|
||||
if (this.debug) {
|
||||
console.log(jsonStr)
|
||||
if (streamDataRes.status === 200) {
|
||||
let streamData = streamDataRes.body
|
||||
// console.log(streamData)
|
||||
let responseText = ''
|
||||
let streams = streamData.split('\n\n')
|
||||
for (let s of streams) {
|
||||
let jsonStr = s.replace('data: ', '').trim()
|
||||
try {
|
||||
let jsonObj = JSON.parse(jsonStr)
|
||||
if (jsonObj && jsonObj.completion) {
|
||||
responseText += jsonObj.completion
|
||||
}
|
||||
if (this.debug) {
|
||||
console.log(jsonObj)
|
||||
}
|
||||
// console.log(responseText)
|
||||
} catch (err) {
|
||||
// ignore error
|
||||
if (this.debug) {
|
||||
console.log(jsonStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
text: responseText.trim(),
|
||||
conversationId
|
||||
return {
|
||||
text: responseText.trim(),
|
||||
conversationId
|
||||
}
|
||||
} else if (streamDataRes.status === 408) {
|
||||
throw new Error('claude.ai响应超时,可能是回复文本太多,请调高超时时间重试')
|
||||
} else {
|
||||
throw new Error('unknown error')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue