浏览代码

Handles undefined message case in message list creation

Prevents potential errors by returning an empty list if the
specified message ID does not exist in the history. This
enhancement ensures robustness in scenarios where a message
ID may be missing, avoiding further processing and potential
exceptions.
Dave 4 月之前
父节点
当前提交
01eedd36bc
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      src/lib/utils/index.ts

+ 3 - 0
src/lib/utils/index.ts

@@ -1225,6 +1225,9 @@ export const createMessagesList = (history, messageId) => {
 	}
 	}
 
 
 	const message = history.messages[messageId];
 	const message = history.messages[messageId];
+	if (message === undefined) {
+		return [];
+	}
 	if (message?.parentId) {
 	if (message?.parentId) {
 		return [...createMessagesList(history, message.parentId), message];
 		return [...createMessagesList(history, message.parentId), message];
 	} else {
 	} else {