fix: minor error handler message

This commit is contained in:
sawhil 2025-04-01 01:24:59 +05:30 committed by Sahil Khan
parent 30b689037a
commit eb9385840f
2 changed files with 8 additions and 10 deletions

View File

@ -10,7 +10,6 @@ import { useGetCompositeQueryParam } from 'hooks/queryBuilder/useGetCompositeQue
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
import useDebouncedFn from 'hooks/useDebouncedFunction'; import useDebouncedFn from 'hooks/useDebouncedFunction';
import { useEventSourceEvent } from 'hooks/useEventSourceEvent'; import { useEventSourceEvent } from 'hooks/useEventSourceEvent';
import { useNotifications } from 'hooks/useNotifications';
import { prepareQueryRangePayload } from 'lib/dashboard/prepareQueryRangePayload'; import { prepareQueryRangePayload } from 'lib/dashboard/prepareQueryRangePayload';
import { useEventSource } from 'providers/EventSource'; import { useEventSource } from 'providers/EventSource';
import { useCallback, useEffect, useRef, useState } from 'react'; import { useCallback, useEffect, useRef, useState } from 'react';
@ -38,8 +37,6 @@ function LiveLogsContainer(): JSX.Element {
const batchedEventsRef = useRef<ILog[]>([]); const batchedEventsRef = useRef<ILog[]>([]);
const { notifications } = useNotifications();
const { selectedTime: globalSelectedTime } = useSelector< const { selectedTime: globalSelectedTime } = useSelector<
AppState, AppState,
GlobalReducer GlobalReducer
@ -88,8 +85,8 @@ function LiveLogsContainer(): JSX.Element {
); );
const handleError = useCallback(() => { const handleError = useCallback(() => {
notifications.error({ message: 'Sorry, something went wrong' }); console.error('Sorry, something went wrong');
}, [notifications]); }, []);
useEventSourceEvent('message', handleGetLiveLogs); useEventSourceEvent('message', handleGetLiveLogs);
useEventSourceEvent('error', handleError); useEventSourceEvent('error', handleError);
@ -157,7 +154,6 @@ function LiveLogsContainer(): JSX.Element {
useEffect((): (() => void) | undefined => { useEffect((): (() => void) | undefined => {
if (isConnectionError && reconnectDueToError && compositeQuery) { if (isConnectionError && reconnectDueToError && compositeQuery) {
console.log('uncaught refetch try from component', reconnectDueToError);
// Small delay to prevent immediate reconnection attempts // Small delay to prevent immediate reconnection attempts
const reconnectTimer = setTimeout(() => { const reconnectTimer = setTimeout(() => {
handleStartNewConnection(compositeQuery); handleStartNewConnection(compositeQuery);

View File

@ -7,6 +7,7 @@ import { ENVIRONMENT } from 'constants/env';
import { LIVE_TAIL_HEARTBEAT_TIMEOUT } from 'constants/liveTail'; import { LIVE_TAIL_HEARTBEAT_TIMEOUT } from 'constants/liveTail';
import { LOCALSTORAGE } from 'constants/localStorage'; import { LOCALSTORAGE } from 'constants/localStorage';
import { EventListener, EventSourcePolyfill } from 'event-source-polyfill'; import { EventListener, EventSourcePolyfill } from 'event-source-polyfill';
import { useNotifications } from 'hooks/useNotifications';
import { import {
createContext, createContext,
PropsWithChildren, PropsWithChildren,
@ -58,6 +59,8 @@ export function EventSourceProvider({
const eventSourceRef = useRef<EventSourcePolyfill | null>(null); const eventSourceRef = useRef<EventSourcePolyfill | null>(null);
const { notifications } = useNotifications();
const handleSetInitialLoading = useCallback((value: boolean) => { const handleSetInitialLoading = useCallback((value: boolean) => {
setInitialLoading(value); setInitialLoading(value);
}, []); }, []);
@ -78,8 +81,6 @@ export function EventSourceProvider({
refreshToken: getLocalStorageApi(LOCALSTORAGE.REFRESH_AUTH_TOKEN) || '', refreshToken: getLocalStorageApi(LOCALSTORAGE.REFRESH_AUTH_TOKEN) || '',
}); });
console.log('uncaught token refresh started', { response });
if (response.statusCode === 200) { if (response.statusCode === 200) {
// Update tokens in local storage // Update tokens in local storage
afterLogin( afterLogin(
@ -96,8 +97,8 @@ export function EventSourceProvider({
return; return;
} }
notifications.error({ message: 'Sorry, something went wrong' });
// If token refresh failed, logout the user // If token refresh failed, logout the user
if (!eventSourceRef.current) return; if (!eventSourceRef.current) return;
eventSourceRef.current.close(); eventSourceRef.current.close();
setIsConnectionError(true); setIsConnectionError(true);
@ -105,13 +106,14 @@ export function EventSourceProvider({
} catch (error) { } catch (error) {
// If there was an error during token refresh, we'll just // If there was an error during token refresh, we'll just
// let the component handle the error state // let the component handle the error state
notifications.error({ message: 'Sorry, something went wrong' });
console.error('Error refreshing token:', error); console.error('Error refreshing token:', error);
setIsConnectionError(true); setIsConnectionError(true);
if (!eventSourceRef.current) return; if (!eventSourceRef.current) return;
eventSourceRef.current.close(); eventSourceRef.current.close();
Logout(); Logout();
} }
}, []); }, [notifications]);
const destroyEventSourceSession = useCallback(() => { const destroyEventSourceSession = useCallback(() => {
if (!eventSourceRef.current) return; if (!eventSourceRef.current) return;