chore: re-arrange addMessage to avoid returning partial error

Strange I can only observe this in prod. Not in local env even using `next build && next start`
This commit is contained in:
Tianzhou Chen
2023-05-06 00:07:51 +08:00
parent ab80b67521
commit 5bb8a232e2

View File

@@ -150,18 +150,6 @@ const ConversationView = () => {
};
messageStore.addMessage(userMessage);
// Add PENDING assistant message to the store.
const assistantMessage: Message = {
id: generateUUID(),
conversationId: currentConversation.id,
creatorId: currentConversation.assistantId,
creatorRole: CreatorRole.Assistant,
createdAt: Date.now(),
content: "",
status: "LOADING",
};
messageStore.addMessage(assistantMessage);
// Construct the system prompt
const messageList = messageStore
.getState()
@@ -264,13 +252,30 @@ const ConversationView = () => {
} catch (error) {
// do nth
}
messageStore.updateMessage(assistantMessage.id, {
messageStore.addMessage({
id: generateUUID(),
conversationId: currentConversation.id,
creatorId: currentConversation.assistantId,
creatorRole: CreatorRole.Assistant,
createdAt: Date.now(),
content: errorMessage,
status: "FAILED",
});
return;
}
// Add PENDING assistant message to the store.
const assistantMessage: Message = {
id: generateUUID(),
conversationId: currentConversation.id,
creatorId: currentConversation.assistantId,
creatorRole: CreatorRole.Assistant,
createdAt: Date.now(),
content: "",
status: "LOADING",
};
messageStore.addMessage(assistantMessage);
const data = rawRes.body;
if (!data) {
toast.error("No data return");