capture streaming error

This commit is contained in:
Philipinho
2025-10-26 01:29:22 +01:00
parent d1fa1443bd
commit c701709434
3 changed files with 21 additions and 1 deletions

View File

@ -53,6 +53,9 @@ export async function askAi(
try { try {
const parsed = JSON.parse(data); const parsed = JSON.parse(data);
if (parsed.error) {
throw new Error(parsed.error);
}
if (parsed.content) { if (parsed.content) {
answer += parsed.content; answer += parsed.content;
onChunk?.({ content: parsed.content }); onChunk?.({ content: parsed.content });
@ -62,6 +65,9 @@ export async function askAi(
onChunk?.({ sources: parsed.sources }); onChunk?.({ sources: parsed.sources });
} }
} catch (e) { } catch (e) {
if (e instanceof Error) {
throw e;
}
// Skip invalid JSON // Skip invalid JSON
} }
} }

View File

@ -4,6 +4,7 @@ import { Group, Button } from "@mantine/core";
import React, { useState, useMemo, useEffect } from "react"; import React, { useState, useMemo, useEffect } from "react";
import { useDebouncedValue } from "@mantine/hooks"; import { useDebouncedValue } from "@mantine/hooks";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { notifications } from "@mantine/notifications";
import { searchSpotlightStore } from "../constants.ts"; import { searchSpotlightStore } from "../constants.ts";
import { SearchSpotlightFilters } from "./search-spotlight-filters.tsx"; import { SearchSpotlightFilters } from "./search-spotlight-filters.tsx";
import { useUnifiedSearch } from "../hooks/use-unified-search.ts"; import { useUnifiedSearch } from "../hooks/use-unified-search.ts";
@ -57,6 +58,8 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
mutate: triggerAiSearchMutation, mutate: triggerAiSearchMutation,
//@ts-ignore //@ts-ignore
reset: resetAiMutation, reset: resetAiMutation,
//@ts-ignore
error: aiSearchError,
streamingAnswer, streamingAnswer,
streamingSources, streamingSources,
clearStreaming, clearStreaming,
@ -68,6 +71,17 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
resetAiMutation(); resetAiMutation();
}, [query, clearStreaming, resetAiMutation]); }, [query, clearStreaming, resetAiMutation]);
// Show error notification when AI search fails
useEffect(() => {
if (aiSearchError) {
notifications.show({
message: aiSearchError.message || t("AI search failed. Please try again."),
color: "red",
position: "top-center"
});
}
}, [aiSearchError, t]);
// Determine result type for rendering // Determine result type for rendering
const isAttachmentSearch = const isAttachmentSearch =
filters.contentType === "attachment" && (hasLicenseKey || isCloud()); filters.contentType === "attachment" && (hasLicenseKey || isCloud());

View File

@ -51,7 +51,7 @@ root.render(
<MantineProvider theme={theme} cssVariablesResolver={mantineCssResolver}> <MantineProvider theme={theme} cssVariablesResolver={mantineCssResolver}>
<ModalsProvider> <ModalsProvider>
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<Notifications position="bottom-center" limit={3} /> <Notifications position="bottom-center" limit={3} zIndex={10000} />
<HelmetProvider> <HelmetProvider>
<PostHogProvider client={posthog}> <PostHogProvider client={posthog}>
<App /> <App />