Log chat errors in supabase
Closed
SS
1y ago+537+537+012345678901234567890123456789-39-39-01234567890123456789
Error logging to the Supabase error_logs table has been implemented for chat errors, mirroring existing Telegram notifications.
- A new function,
insertErrorLog, was created inlib/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 theerror_logstable. - The existing
sendErrorNotificationfunction inlib/telegram/errors/sendErrorNotification.tswas modified. It now first sends the error to Telegram, captures themessage_id, and then callsinsertErrorLogto save the error to Supabase, linking it via thetelegram_message_id. Additional optional parameters likeaccountIdandtoolNamewere added to its interface for richer context. - The
app/api/chat/route.tsfile was updated. All three error handling points (onFinish,onError, and the globalcatch) now pass a specificpathstring (e.g.,"/api/chat - onFinish") tosendErrorNotificationfor improved error traceability.
This ensures every chat error is now logged to both Telegram and Supabase, with cross-referencing capabilities.