Skip to content

Commit 2f7e745

Browse files
committed
fix: backend error
1 parent fb1365d commit 2f7e745

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/services/parsers/parseMultipart.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function parseMultipart({
5858
const data = responseText;
5959
const boundaryStr = `--${boundary}${CRLF}`;
6060
let pos = lastProcessedLength;
61+
let lastProcessedPos = pos;
6162
const chunks: StreamingChunk[] = [];
6263

6364
while (pos < data.length) {
@@ -87,22 +88,27 @@ export function parseMultipart({
8788
}
8889

8990
// Extract content
90-
const content = data.slice(contentStart, contentEnd);
91+
let content = data.slice(contentStart, contentEnd);
9192

9293
// Try to parse JSON content
9394
try {
9495
const parsedChunk = JSON.parse(content) as StreamingChunk;
9596
chunks.push(parsedChunk);
9697
} catch {
98+
// try parse last chunk (has error with --boundary-- in content length)
99+
content = data.slice(contentStart, contentEnd - '--boundary--'.length);
100+
const parsedChunk = JSON.parse(content) as StreamingChunk;
101+
chunks.push(parsedChunk);
97102
// Invalid JSON, skip this chunk
98103
}
99104

100105
// Move position to end of content
101106
pos = contentEnd;
107+
lastProcessedPos = pos;
102108
}
103109

104110
return {
105111
chunks,
106-
lastProcessedLength: pos,
112+
lastProcessedLength: lastProcessedPos,
107113
};
108114
}

src/store/reducers/query/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ interface QueryStats {
259259
endTime?: string | number;
260260
}
261261

262-
const DEFAULT_STREAM_CHUNK_SIZE = 100;
262+
const DEFAULT_STREAM_CHUNK_SIZE = 2;
263263
const DEFAULT_CONCURRENT_RESULTS = false;
264264

265265
export const queryApi = api.injectEndpoints({

0 commit comments

Comments
 (0)