fix: image request error message

This commit is contained in:
jialin
2024-11-29 10:58:16 +08:00
parent 0cc2a40f26
commit 890287ce72
14 changed files with 145 additions and 69 deletions
+6 -6
View File
@@ -114,7 +114,7 @@ export const readLargeStreamData = async (
let buffer = ''; // cache incomplete line
while (true) {
const { done, value } = await reader.read();
const { done, value } = await reader?.read?.();
if (done) {
// Process remaining buffered data
if (buffer.trim()) {
@@ -131,14 +131,14 @@ export const readLargeStreamData = async (
buffer = lines.pop() || ''; // Keep last line (may be incomplete)
for (const line of lines) {
if (line === '[DONE]') {
continue;
}
if (line.startsWith('data: ')) {
const jsonStr = line.slice(6).trim();
try {
const jsonData = JSON.parse(jsonStr);
callback(jsonData);
if (jsonStr !== '[DONE]') {
const jsonData = JSON.parse(jsonStr);
callback(jsonData);
}
} catch (e) {
console.error('Failed to parse JSON:', jsonStr, e);
}