Next.js Discord

Discord Forum

AI SDK useChat

Unanswered
Sanderling posted this in #help-forum
Open in Discord
SanderlingOP
I am using useChat hook. Got one more thing to ask if anyone knows how to handle return statements from api/chat/route.ts that is not a StreamingTextResponse.

Example, in my api/chat/route.ts I am doing some checking if a file exists in a database

const file = await prisma.file.findFirst();

if (!file) {
  return new NextResponse("Bad request", {status: 400})
}

// Do some things here

return new StreamingTextResponse(stream);


How do I handle in the frontend/client component if the file does not exist and the returns the bad request response? In the client side I want to show a Toast message.

1 Reply