mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: better errors feedback
This commit is contained in:
parent
af7d5edd80
commit
854c7dd415
5 changed files with 118 additions and 35 deletions
|
|
@ -5,12 +5,18 @@ export const AIChatBotContext = createContext(null) as any;
|
|||
export const AIChatBotDispatchContext = createContext(null) as any;
|
||||
|
||||
export type AIChatBotStateTypes = {
|
||||
|
||||
messages: AIMessage[],
|
||||
isModalOpen: boolean,
|
||||
aichat_uuid: string,
|
||||
isWaitingForResponse: boolean,
|
||||
chatInputValue: string
|
||||
error: AIError
|
||||
}
|
||||
|
||||
type AIError = {
|
||||
isError: boolean
|
||||
status: number
|
||||
error_message: string
|
||||
}
|
||||
|
||||
function AIChatBotProvider({ children }: { children: React.ReactNode }) {
|
||||
|
|
@ -20,7 +26,8 @@ function AIChatBotProvider({ children }: { children: React.ReactNode }) {
|
|||
isModalOpen: false,
|
||||
aichat_uuid: null,
|
||||
isWaitingForResponse: false,
|
||||
chatInputValue: ''
|
||||
chatInputValue: '',
|
||||
error: { isError: false, status: 0, error_message: ' ' } as AIError
|
||||
}
|
||||
);
|
||||
return (
|
||||
|
|
@ -60,6 +67,8 @@ function aiChatBotReducer(state: any, action: any) {
|
|||
return { ...state, isWaitingForResponse: false };
|
||||
case 'setChatInputValue':
|
||||
return { ...state, chatInputValue: action.payload };
|
||||
case 'setError':
|
||||
return { ...state, error: action.payload };
|
||||
|
||||
default:
|
||||
throw new Error(`Unhandled action type: ${action.type}`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue