fix: send error messages before throwing error

This commit is contained in:
Index 2025-11-09 22:29:26 -06:00
parent 8ac057b80a
commit 92bdb975d9
2 changed files with 6 additions and 4 deletions

View file

@ -115,7 +115,7 @@ export async function handler(message: ChatMessage): Promise<void> {
: env.AUTHORIZED_USERS.includes(message.senderDid as any); : env.AUTHORIZED_USERS.includes(message.senderDid as any);
if (!authorized) { if (!authorized) {
conversation.sendMessage({ await conversation.sendMessage({
text: c.UNAUTHORIZED_MESSAGE, text: c.UNAUTHORIZED_MESSAGE,
}); });
@ -157,7 +157,8 @@ export async function handler(message: ChatMessage): Promise<void> {
parsedConversation.messages, parsedConversation.messages,
); );
if (!inference) { if (!inference) {
throw new Error("Failed to generate text. Returned undefined."); logger.error("Failed to generate text. Returned undefined.");
return;
} }
const responseText = inference.text; const responseText = inference.text;

View file

@ -31,10 +31,11 @@ async function initConvo(convo: Conversation, initialMessage: ChatMessage) {
const postUri = await parseMessagePostUri(initialMessage); const postUri = await parseMessagePostUri(initialMessage);
if (!postUri) { if (!postUri) {
convo.sendMessage({ await convo.sendMessage({
text: text:
"Please send a post for me to make sense of the noise for you.", "Please send a post for me to make sense of the noise for you.",
}); });
throw new Error("No post reference in initial message."); throw new Error("No post reference in initial message.");
} }
@ -136,7 +137,7 @@ export async function parseConversation(
}), }),
}; };
} catch (e) { } catch (e) {
convo.sendMessage({ await convo.sendMessage({
text: ERROR_MESSAGE, text: ERROR_MESSAGE,
}); });