mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +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) {
|
if (streamDataRes.status === 307) {
|
||||||
throw new Error('claude.ai目前不支持你所在的地区')
|
throw new Error('claude.ai目前不支持你所在的地区')
|
||||||
}
|
}
|
||||||
let streamData = streamDataRes.body
|
if (streamDataRes.status === 200) {
|
||||||
// console.log(streamData)
|
let streamData = streamDataRes.body
|
||||||
let responseText = ''
|
// console.log(streamData)
|
||||||
let streams = streamData.split('\n\n')
|
let responseText = ''
|
||||||
for (let s of streams) {
|
let streams = streamData.split('\n\n')
|
||||||
let jsonStr = s.replace('data: ', '').trim()
|
for (let s of streams) {
|
||||||
try {
|
let jsonStr = s.replace('data: ', '').trim()
|
||||||
let jsonObj = JSON.parse(jsonStr)
|
try {
|
||||||
if (jsonObj && jsonObj.completion) {
|
let jsonObj = JSON.parse(jsonStr)
|
||||||
responseText += jsonObj.completion
|
if (jsonObj && jsonObj.completion) {
|
||||||
}
|
responseText += jsonObj.completion
|
||||||
if (this.debug) {
|
}
|
||||||
console.log(jsonObj)
|
if (this.debug) {
|
||||||
}
|
console.log(jsonObj)
|
||||||
// console.log(responseText)
|
}
|
||||||
} catch (err) {
|
// console.log(responseText)
|
||||||
// ignore error
|
} catch (err) {
|
||||||
if (this.debug) {
|
// ignore error
|
||||||
console.log(jsonStr)
|
if (this.debug) {
|
||||||
|
console.log(jsonStr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return {
|
||||||
return {
|
text: responseText.trim(),
|
||||||
text: responseText.trim(),
|
conversationId
|
||||||
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