When I have a problem with my backend (eg. server is offline), I get this console error:
AppLayoutClient.tsx:43 CopilotKit Error (hidden in production): Agent 'sample_agent' was not found. Please set up at least one agent before proceeding. See more: [https://docs.copilotkit.ai/coagents/troubleshooting/common-issues#i-am-gett…
To be able to handle this and show an error message to the user, I've added this to the code:
<CopilotKit
publicApiKey={copilotkitPublicApiKey}
agent="sample_agent"
onError={(error: unknown) => {
toast.error(
error instanceof Error
? error.message
: 'Could not connect to AI assistant',
);
}}
>
But the onError function is not being called. I still see the error message on the console, but any code I add to the onError function (including a simple console.log for sanity check) doesn't get executed.