fix: log message json pares error

This commit is contained in:
Joel
2023-08-28 17:31:04 +08:00
parent c2d8c9010a
commit e8294d2e38

View File

@ -64,7 +64,16 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
lines.forEach((message) => {
if (!message || !message.startsWith('data: '))
return
bufferObj = JSON.parse(message.substring(6)) // remove data: and parse as json
try {
bufferObj = JSON.parse(message.substring(6)) // remove data: and parse as json
} catch (e) {
// mute handle message cut off
onData('', isFirstMessage, {
conversationId: bufferObj?.conversation_id,
messageId: bufferObj?.id,
})
return
}
if (bufferObj.event !== 'message')
return