diff --git a/next/src/hooks/useAgent.ts b/next/src/hooks/useAgent.ts index 2917725a88..a0dda546f8 100644 --- a/next/src/hooks/useAgent.ts +++ b/next/src/hooks/useAgent.ts @@ -22,19 +22,23 @@ export function useAgent(): AgentUtils { }); const createAgent = async (data: CreateAgentProps): Promise => { if (status === "authenticated") { - return await createMutation.mutateAsync(data); - } else { - return undefined; + try { + return await createMutation.mutateAsync(data); + } catch (error) { + console.error("Failed to create agent:", error); + // Optionally, you could return an error object or notify the user + } } + return undefined; }; - - const saveMutation = api.agent.save.useMutation(); + const saveAgent = (data: SaveAgentProps) => { - if (status === "authenticated") saveMutation.mutate(data); - }; - - return { - createAgent, - saveAgent, + if (status === "authenticated") { + saveMutation.mutate(data, { + onError: (error) => { + console.error("Failed to save agent:", error); + }, + }); + } }; -} + \ No newline at end of file