Skip to content

Commit

Permalink
clear context when spark return error
Browse files Browse the repository at this point in the history
  • Loading branch information
samanhappy committed Nov 25, 2023
1 parent 3ed50a8 commit 49976e7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bots/SparkBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ export default class SparkBot extends Bot {
);

let text = "";
let error = false;
source.addEventListener("message", (event) => {
if (event.data === "<end>") {
onUpdateResponse(callbackParam, { done: true });
source.close();
resolve();
} else if (event.data === "[error]") {
error = true;
} else if (event.data.slice(-5) === "<sid>") {
// ignore <sid> message
return;
Expand All @@ -111,6 +114,11 @@ export default class SparkBot extends Bot {
}
text += partialText;
onUpdateResponse(callbackParam, { content: text, done: false });

// clear context if error
if (error) {
this.setChatContext(null);
}
}
});

Expand Down

0 comments on commit 49976e7

Please sign in to comment.