Skip to content

Commit

Permalink
fix(abortMiddleware): handle early abort error where userMessage.conv…
Browse files Browse the repository at this point in the history
…ersationId is undefined. In this case, the userId will be used as the abortKey
  • Loading branch information
danny-avila committed Aug 18, 2023
1 parent c74c68a commit 3c7f67f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions api/server/middleware/abortMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ const createAbortController = (res, req, endpointOption, getAbortData) => {
const abortController = new AbortController();
const onStart = (userMessage) => {
sendMessage(res, { message: userMessage, created: true });
abortControllers.set(userMessage.conversationId, { abortController, ...endpointOption });
const abortKey = userMessage?.conversationId ?? req.user.id;
abortControllers.set(abortKey, { abortController, ...endpointOption });

res.on('finish', function () {
abortControllers.delete(userMessage.conversationId);
abortControllers.delete(abortKey);
});
};

Expand Down

0 comments on commit 3c7f67f

Please sign in to comment.