Log chat errors in supabase

Closed
SS
1y ago
+537-39

Error logging to the Supabase error_logs table has been implemented for chat errors, mirroring existing Telegram notifications.

  • A new function, insertErrorLog, was created in lib/supabase/error_logs/insertErrorLog.ts. This function handles inserting comprehensive error details, including user context, chat messages, error type, stack trace, and a full JSON payload, into the error_logs table.
  • The existing sendErrorNotification function in lib/telegram/errors/sendErrorNotification.ts was modified. It now first sends the error to Telegram, captures the message_id, and then calls insertErrorLog to save the error to Supabase, linking it via the telegram_message_id. Additional optional parameters like accountId and toolName were added to its interface for richer context.
  • The app/api/chat/route.ts file was updated. All three error handling points (onFinish, onError, and the global catch) now pass a specific path string (e.g., "/api/chat - onFinish") to sendErrorNotification for improved error traceability.

This ensures every chat error is now logged to both Telegram and Supabase, with cross-referencing capabilities.