Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

[API] Fix: Input validation failed: error message inside JSON body was not displaying correctly #276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/features/Apiexplorer/SubscribeRenderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ function SubscribeRenderer<T extends TSocketSubscribableEndpointNames>({
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]);
Expand Down
17 changes: 16 additions & 1 deletion src/hooks/useSubscription/__tests__/useSubscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
9 changes: 2 additions & 7 deletions src/hooks/useSubscription/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import {
} from '@site/src/configs/websocket/types';
import { useCallback, useState } from 'react';

type TError = {
code?: string;
message?: string;
};

const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T) => {
const [is_loading, setIsLoading] = useState(false);
const [is_subscribed, setSubscribed] = useState(false);
const [error, setError] = useState<TError>();
const [error, setError] = useState<unknown>();
const [data, setData] = useState<TSocketResponseData<T>>();
const [full_response, setFullResponse] = useState<TSocketResponse<T>>();
const [subscriber, setSubscriber] = useState<{ unsubscribe?: VoidFunction }>();
Expand All @@ -30,7 +25,7 @@ const useSubscription = <T extends TSocketSubscribableEndpointNames>(name: T) =>
);

const onError = useCallback((response: TSocketResponse<T>) => {
setError(response.error);
setError(response);
setIsLoading(false);
setFullResponse(null);
}, []);
Expand Down