Skip to content

Commit

Permalink
fix: chunk processing in Chat component (#289)
Browse files Browse the repository at this point in the history
* fix: chunk processing in Chat component.

* chore: format and lint the code
  • Loading branch information
a0m0rajab committed Jan 12, 2024
1 parent 2d61626 commit f1c29ff
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/repo-query/pages/chat.tsx
Expand Up @@ -18,15 +18,16 @@ export const Chat = ({ ownerName, repoName }: { ownerName: string, repoName: str

const processChunk = (chunk: string) => {
const chunkLines = chunk.split("\n");
const [eventLine, dataLine] = chunkLines;
const indexOfEvent = chunkLines.findIndex(e => e.includes("event: "));
const [eventLine, dataLine] = [chunkLines[indexOfEvent], chunkLines[indexOfEvent + 1]];

const event = eventLine.split(": ")[1];
let data:any;

try {
data = JSON.parse(dataLine.split(": ")[1]);
} catch (e) {
console.error(dataLine);
console.error("The recieved data line", dataLine);

// remove quotes from string
data = dataLine.split("data: ")[1].substring(1, dataLine.split("data: ")[1].length - 2);
Expand Down

0 comments on commit f1c29ff

Please sign in to comment.