useChat "An error occurred"
Troubleshooting errors related to the "An error occurred" error in useChat.
Issue
I am using useChat and I get the error "An error occurred".
Background
Error messages from streamText are masked by default when using toUIMessageStream for security reasons (secure-by-default).
This prevents leaking sensitive information to the client.
Solution
To forward error details to the client or to log errors, use the onError function when calling toUIMessageStream.
In case you are using createUIMessageStream, you can pass the onError function to it: