diff --git a/src/features/Apiexplorer/SubscribeRenderer/index.tsx b/src/features/Apiexplorer/SubscribeRenderer/index.tsx index 912a90f5..a107da74 100644 --- a/src/features/Apiexplorer/SubscribeRenderer/index.tsx +++ b/src/features/Apiexplorer/SubscribeRenderer/index.tsx @@ -32,7 +32,12 @@ function SubscribeRenderer({ const [is_not_valid, setIsNotValid] = useState(false); useEffect(() => { - if (error && error.code === 'AuthorizationRequired') { + if ( + error && + typeof error === 'object' && + 'code' in error && + error.code === 'AuthorizationRequired' + ) { setToggleModal(true); } }, [error]); diff --git a/src/hooks/useSubscription/__tests__/useSubscription.test.tsx b/src/hooks/useSubscription/__tests__/useSubscription.test.tsx index d3e9c250..d19080de 100644 --- a/src/hooks/useSubscription/__tests__/useSubscription.test.tsx +++ b/src/hooks/useSubscription/__tests__/useSubscription.test.tsx @@ -206,7 +206,22 @@ describe('Use WS', () => { }, }); - expect(result.current.error).toEqual({ message: 'this is an error' }); + expect(result.current.error).toEqual({ + echo_req: { + base_currency: 'USD', + exchange_rates: 1, + req_id: 1, + subscribe: 1, + }, + error: { + message: 'this is an error', + }, + msg_type: 'exchange_rates', + req_id: 1, + subscription: { + id: '2f39f7e7-d986-33f2-080a-b0ee50cfb85c', + }, + }); expect(result.current.is_loading).toBeFalsy(); }); }); diff --git a/src/hooks/useSubscription/index.tsx b/src/hooks/useSubscription/index.tsx index 06b25cbd..1051a86a 100644 --- a/src/hooks/useSubscription/index.tsx +++ b/src/hooks/useSubscription/index.tsx @@ -6,15 +6,10 @@ import { } from '@site/src/configs/websocket/types'; import { useCallback, useState } from 'react'; -type TError = { - code?: string; - message?: string; -}; - const useSubscription = (name: T) => { const [is_loading, setIsLoading] = useState(false); const [is_subscribed, setSubscribed] = useState(false); - const [error, setError] = useState(); + const [error, setError] = useState(); const [data, setData] = useState>(); const [full_response, setFullResponse] = useState>(); const [subscriber, setSubscriber] = useState<{ unsubscribe?: VoidFunction }>(); @@ -30,7 +25,7 @@ const useSubscription = (name: T) => ); const onError = useCallback((response: TSocketResponse) => { - setError(response.error); + setError(response); setIsLoading(false); setFullResponse(null); }, []);