fix: add reducers to raise error, handle complete_stream()

This commit is contained in:
ManishMadan2882
2024-06-20 00:10:29 +05:30
parent 69287c5198
commit ad29d2765f
2 changed files with 55 additions and 30 deletions

View File

@@ -68,6 +68,15 @@ export const fetchAnswer = createAsyncThunk<Answer, { question: string }>(
query: { conversationId: data.id },
}),
);
} else if (data.type === 'error') {
// set status to 'failed'
dispatch(conversationSlice.actions.setStatus('failed'));
dispatch(
conversationSlice.actions.raiseError({
index: state.conversation.queries.length - 1,
message: data.error,
}),
);
} else {
const result = data.answer;
dispatch(
@@ -191,6 +200,13 @@ export const conversationSlice = createSlice({
setStatus(state, action: PayloadAction<Status>) {
state.status = action.payload;
},
raiseError(
state,
action: PayloadAction<{ index: number; message: string }>,
) {
const { index, message } = action.payload;
state.queries[index].error = message;
},
},
extraReducers(builder) {
builder