Skip to content

Commit 85c9327

Browse files
committed
feat(docs): surface backend error frames in docs ask widget
1 parent c70e823 commit 85c9327

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

docs/src/components/AztecDocsWidget/Message.jsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function AssistantBody({
3333
text,
3434
sources,
3535
thinking,
36+
error,
3637
tokens,
3738
mdComponents,
3839
feedback,
@@ -144,6 +145,26 @@ export function AssistantBody({
144145
</ReactMarkdown>
145146
) : null}
146147
</div>
148+
{error && (
149+
<div
150+
role="alert"
151+
style={{
152+
marginTop: text ? 10 : 0,
153+
padding: "8px 10px",
154+
border: `1px solid var(--azw-vermillion, ${accentColor})`,
155+
background: isInk
156+
? "rgba(217, 74, 58, 0.12)"
157+
: "rgba(217, 74, 58, 0.08)",
158+
color: "var(--azw-vermillion, #d94a3a)",
159+
fontFamily: "var(--azw-font-sans)",
160+
fontSize: 12.5,
161+
lineHeight: 1.45,
162+
letterSpacing: "-0.01em",
163+
}}
164+
>
165+
{error}
166+
</div>
167+
)}
147168
{sources?.length > 0 && (
148169
<div style={{ marginTop: 10 }}>
149170
<div

docs/src/components/AztecDocsWidget/Panel.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,18 @@ export default function Panel({
228228
const text = isLast && streaming ? streamText : m.response;
229229
const sources = isLast && streaming ? streamSources : m.sources;
230230
const isStreamingLast = isLast && streaming;
231+
const error = isStreamingLast ? null : m.error;
231232
const showFeedback =
232233
!isStreamingLast && !!m.response && !!conversationId;
233234
return (
234235
<React.Fragment key={i}>
235236
<UserBubble text={m.prompt} tokens={tokens} />
236-
{(text || isStreamingLast) && (
237+
{(text || isStreamingLast || error) && (
237238
<AssistantBody
238239
text={text}
239240
sources={sources}
240241
thinking={isStreamingLast}
242+
error={error}
241243
tokens={tokens}
242244
mdComponents={mdComponents}
243245
showFeedback={showFeedback}

docs/src/components/AztecDocsWidget/index.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default function AztecDocsWidget({
7373

7474
let acc = "";
7575
let sources = [];
76+
let errorMessage = null;
7677
try {
7778
await streamAnswer({
7879
apiHost,
@@ -90,18 +91,27 @@ export default function AztecDocsWidget({
9091
setStreamSources(sources);
9192
},
9293
onConversationId: (id) => setConversationId(id),
94+
onError: (message) => {
95+
errorMessage = message;
96+
},
9397
onDone: () => {},
9498
});
9599
} catch (err) {
96100
if (err.name !== "AbortError") {
97-
acc =
98-
acc || "Something went wrong fetching an answer. Please try again.";
101+
errorMessage =
102+
errorMessage ||
103+
"Something went wrong fetching an answer. Please try again.";
99104
}
100105
}
101106

102107
setMessages((prev) => {
103108
const copy = [...prev];
104-
copy[copy.length - 1] = { prompt: question, response: acc, sources };
109+
copy[copy.length - 1] = {
110+
prompt: question,
111+
response: acc,
112+
sources,
113+
error: errorMessage,
114+
};
105115
return copy;
106116
});
107117
setStreaming(false);

docs/src/components/AztecDocsWidget/streamAnswer.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export async function streamAnswer({
77
onToken,
88
onSource,
99
onConversationId,
10+
onError,
1011
onDone,
1112
signal,
1213
}) {
@@ -56,6 +57,14 @@ export async function streamAnswer({
5657
onSource(sources);
5758
} else if (parsed.type === "id" && parsed.id) {
5859
onConversationId(parsed.id);
60+
} else if (parsed.type === "error") {
61+
const message =
62+
typeof parsed.error === "string" && parsed.error.trim()
63+
? parsed.error
64+
: "Something went wrong generating an answer.";
65+
onError?.(message);
66+
onDone();
67+
return;
5968
} else if (parsed.type === "end") {
6069
onDone();
6170
return;

0 commit comments

Comments
 (0)