Skip to content

Commit

Permalink
handle parsing error
Browse files Browse the repository at this point in the history
  • Loading branch information
AyushAgrawal-A2 committed Jan 10, 2025
1 parent 9311270 commit 8f03c26
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions quadratic-client/src/app/ai/hooks/useAIRequestToAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ export function useAIRequestToAPI() {
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const newResponseMessage = AIMessagePromptSchema.parse(JSON.parse(line.slice(6)));
setMessages?.((prev) => [...prev.slice(0, -1), { ...newResponseMessage }]);
responseMessage = newResponseMessage;
try {
const newResponseMessage = AIMessagePromptSchema.parse(JSON.parse(line.slice(6)));
setMessages?.((prev) => [...prev.slice(0, -1), { ...newResponseMessage }]);
responseMessage = newResponseMessage;
} catch (error) {
console.error('Error parsing AI response: ', { error, line, lines });
}
}
}
}
Expand Down

0 comments on commit 8f03c26

Please sign in to comment.