mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-28 13:32:23 +00:00
Enhance error handling and connection management in Telegram components
- Added console error logging in TelegramConnectionModal for better debugging during authentication failures. - Updated connection status check in TelegramProvider to only verify once when connected, improving efficiency. - Simplified socket connection logic in socketService by removing unnecessary checks and reducing timeout for initial connection. This update improves error visibility and optimizes connection handling, enhancing the overall user experience during Telegram interactions.
This commit is contained in:
@@ -155,6 +155,7 @@ const TelegramConnectionModal = ({
|
||||
},
|
||||
async (err) => {
|
||||
// Handle errors
|
||||
console.error("[mtproto] signInWithQrCode error:", err);
|
||||
const errorMessage = err.message || "Authentication error";
|
||||
|
||||
// Check if it's a 2FA password needed error
|
||||
@@ -208,6 +209,7 @@ const TelegramConnectionModal = ({
|
||||
onComplete();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
console.error("[mtproto] Telegram login flow failed:", err);
|
||||
setIsAuthenticating(false);
|
||||
const errorMessage =
|
||||
err instanceof Error ? err.message : "Authentication failed";
|
||||
|
||||
@@ -131,7 +131,7 @@ const TelegramProvider = ({ children }: TelegramProviderProps) => {
|
||||
userId,
|
||||
]);
|
||||
|
||||
// Check connection status periodically to keep user online
|
||||
// Check connection status once when Telegram reports as connected
|
||||
useEffect(() => {
|
||||
if (
|
||||
!shouldSetupTelegram ||
|
||||
@@ -151,9 +151,6 @@ const TelegramProvider = ({ children }: TelegramProviderProps) => {
|
||||
};
|
||||
|
||||
checkConnection();
|
||||
const interval = setInterval(checkConnection, 20000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [shouldSetupTelegram, isInitialized, connectionStatus, userId]);
|
||||
|
||||
const checkConnection = async (): Promise<boolean> => {
|
||||
|
||||
@@ -19,14 +19,10 @@ class SocketService {
|
||||
* Connect to the socket server with authentication
|
||||
*/
|
||||
connect(token: string): void {
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
if (!token) return;
|
||||
|
||||
// Don't connect if already connected with the same token
|
||||
if (this.socket?.connected && this.token === token) {
|
||||
return;
|
||||
}
|
||||
if (this.socket?.connected && this.token === token) return;
|
||||
|
||||
// Disconnect existing connection if token changed or socket exists
|
||||
if (this.socket) {
|
||||
@@ -66,7 +62,7 @@ class SocketService {
|
||||
reconnectionDelay: 1000,
|
||||
reconnectionAttempts: 5,
|
||||
forceNew: true, // Force new connection to ensure auth is sent
|
||||
timeout: 20000, // Increase timeout for initial connection
|
||||
timeout: 2000, // Increase timeout for initial connection
|
||||
upgrade: true, // Allow upgrade from polling to websocket
|
||||
query: {}, // Explicitly prevent token from being added to query string
|
||||
};
|
||||
@@ -77,6 +73,7 @@ class SocketService {
|
||||
this.socket.on("connect", () => {
|
||||
const socketId = this.socket?.id || null;
|
||||
const uid = getSocketUserId();
|
||||
console.log("connected", socketId, uid);
|
||||
store.dispatch(setStatusForUser({ userId: uid, status: "connected" }));
|
||||
store.dispatch(setSocketIdForUser({ userId: uid, socketId }));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user