fix(FN-920): improve error handling in subtask breakdown SSE stream
- Handle empty error messages in subtask-breakdown session by falling back to 'Unknown error' - Fix backend SSE routes to coerce error data to string and handle missing message - Improve frontend connectSubtaskStream to validate parsed error data before displaying - Add tests for error display in SubtaskBreakdownModal component
This commit is contained in:
@@ -1599,7 +1599,13 @@ export function connectSubtaskStream(
|
||||
eventSource.addEventListener("error", (event: Event) => {
|
||||
try {
|
||||
const messageEvent = event as MessageEvent;
|
||||
handlers.onError?.(JSON.parse(messageEvent.data) as string);
|
||||
const parsedData = JSON.parse(messageEvent.data);
|
||||
const errorMessage = typeof parsedData === "string" && parsedData.length > 0 ? parsedData : null;
|
||||
if (errorMessage) {
|
||||
handlers.onError?.(errorMessage);
|
||||
} else {
|
||||
handlers.onError?.("Stream error");
|
||||
}
|
||||
} catch {
|
||||
handlers.onError?.("Stream error");
|
||||
}
|
||||
|
||||
@@ -373,4 +373,21 @@ describe("SubtaskBreakdownModal", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("error handling", () => {
|
||||
it("displays error message when stream returns error event", async () => {
|
||||
renderModal();
|
||||
await waitFor(() => expect(streamHandlers).toBeDefined());
|
||||
streamHandlers.onError("Something went wrong");
|
||||
expect(await screen.findByText("Something went wrong")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows Stream error fallback when receiving empty error", async () => {
|
||||
renderModal();
|
||||
await waitFor(() => expect(streamHandlers).toBeDefined());
|
||||
// In real flow, api.ts converts empty string to "Stream error" before calling onError
|
||||
streamHandlers.onError("Stream error");
|
||||
expect(await screen.findByText("Stream error")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user