feat: improve error messages (#1006)
This commit is contained in:
parent
9127e1be88
commit
8a7d3e9950
13 changed files with 370 additions and 174 deletions
|
|
@ -6,7 +6,7 @@ import { useEffect, useState } from 'react';
|
|||
import useSWR, { useSWRConfig } from 'swr';
|
||||
import { ChatHeader } from '@/components/chat-header';
|
||||
import type { Vote } from '@/lib/db/schema';
|
||||
import { fetcher, generateUUID } from '@/lib/utils';
|
||||
import { fetcher, fetchWithErrorHandlers, generateUUID } from '@/lib/utils';
|
||||
import { Artifact } from './artifact';
|
||||
import { MultimodalInput } from './multimodal-input';
|
||||
import { Messages } from './messages';
|
||||
|
|
@ -19,6 +19,7 @@ import type { Session } from 'next-auth';
|
|||
import { useSearchParams } from 'next/navigation';
|
||||
import { useChatVisibility } from '@/hooks/use-chat-visibility';
|
||||
import { useAutoResume } from '@/hooks/use-auto-resume';
|
||||
import { ChatSDKError } from '@/lib/errors';
|
||||
|
||||
export function Chat({
|
||||
id,
|
||||
|
|
@ -62,6 +63,7 @@ export function Chat({
|
|||
experimental_throttle: 100,
|
||||
sendExtraMessageFields: true,
|
||||
generateId: generateUUID,
|
||||
fetch: fetchWithErrorHandlers,
|
||||
experimental_prepareRequestBody: (body) => ({
|
||||
id,
|
||||
message: body.messages.at(-1),
|
||||
|
|
@ -72,10 +74,12 @@ export function Chat({
|
|||
mutate(unstable_serialize(getChatHistoryPaginationKey));
|
||||
},
|
||||
onError: (error) => {
|
||||
toast({
|
||||
type: 'error',
|
||||
description: error.message,
|
||||
});
|
||||
if (error instanceof ChatSDKError) {
|
||||
toast({
|
||||
type: 'error',
|
||||
description: error.message,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue