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
- With no error, there is no
#errorline - After
#busy,#errorsays Mitra is busy and shows no JSON - After
#crash,#errorsays Mitra could not answer - After
#fineworks, the error line is gone and#statussaysready
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.