Command Palette

Search for a command to run...

Hectal
Phase 5: The Vercel AI SDK
AI Frontend · Exercise 3 of 6 PreviousNext
Intermediate

Friendly Errors with useChat

Three buttons send different questions. #fine works. #busy makes the route answer 429. #crash makes the route throw (a 500).

Show the failure in #error (and nothing when there is no error): Mitra is busy. Please try again in a moment. for a 429, and Mitra could not answer. Please try again. for any other failure. Never show the server's raw text. The error from useChat has a statusCode.

What Check tests

  1. With no error, there is no #error line
  2. After #busy, #error says Mitra is busy and shows no JSON
  3. After #crash, #error says Mitra could not answer
  4. After #fine works, the error line is gone and #status says ready

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.