Skip to content

Commit d60433e

Browse files
chore: fix error output on message send
1 parent 21ccc63 commit d60433e

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/components/agent-preview-react.tsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,29 +221,37 @@ export function AgentPreviewReact(props: {
221221
if (!content) return;
222222
setQuery('');
223223

224-
// Add the most recent user message to the chat window
225-
setMessages((prev) => [...prev, { role: 'user', content, timestamp: new Date() }]);
226-
setIsTyping(true);
227-
const response = await agent.send(sessionId, content);
228-
setResponses((prev) => [...prev, response]);
229-
const message = response.messages[0].message;
224+
try {
225+
// Add the most recent user message to the chat window
226+
setMessages((prev) => [...prev, { role: 'user', content, timestamp: new Date() }]);
227+
setIsTyping(true);
228+
const response = await agent.send(sessionId, content);
229+
setResponses((prev) => [...prev, response]);
230+
const message = response.messages[0].message;
230231

231-
if (!message) {
232-
throw new Error('Failed to send message');
233-
}
234-
setIsTyping(false);
232+
if (!message) {
233+
throw new Error('Failed to send message');
234+
}
235+
setIsTyping(false);
235236

236-
// Add the agent's response to the chat
237-
setMessages((prev) => [...prev, { role: name, content: message, timestamp: new Date() }]);
237+
// Add the agent's response to the chat
238+
setMessages((prev) => [...prev, { role: name, content: message, timestamp: new Date() }]);
238239

239-
// If there is an apex debug log entry, get the log and write it to the output dir
240-
if (response.apexDebugLog && tempDir) {
241-
// Write the apex debug to the output dir
242-
await writeDebugLog(connection, response.apexDebugLog, tempDir);
243-
const logId = response.apexDebugLog.Id;
244-
if (logId) {
245-
setApexDebugLogs((prev) => [...prev, path.join(tempDir, `${logId}.log`)]);
240+
// If there is an apex debug log entry, get the log and write it to the output dir
241+
if (response.apexDebugLog && tempDir) {
242+
// Write the apex debug to the output dir
243+
await writeDebugLog(connection, response.apexDebugLog, tempDir);
244+
const logId = response.apexDebugLog.Id;
245+
if (logId) {
246+
setApexDebugLogs((prev) => [...prev, path.join(tempDir, `${logId}.log`)]);
247+
}
246248
}
249+
} catch (e) {
250+
const sfError = SfError.wrap(e);
251+
setIsTyping(false);
252+
setHeader(`Error: ${sfError.name}`);
253+
setMessages([{ role: name, content: `${sfError.name} - ${sfError.message}`, timestamp: new Date() }]);
254+
setSessionEnded(true);
247255
}
248256
}}
249257
/>

0 commit comments

Comments
 (0)