better handling leaderboard api failure

This commit is contained in:
noumantahir 2022-05-21 12:37:25 +05:00
parent 00d55dfb46
commit c8d6ecd5b3
2 changed files with 14 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import { FilterBar } from '../../filterBar';
import FILTER_OPTIONS, { VALUE } from '../../../constants/options/leaderboard';
// Styles
import styles from './leaderboardStyles';
import EmptyScreenView from '../../basicUIElements/view/emptyScreen/emptyScreenView';
class LeaderboardView extends PureComponent {
/* Props
@ -40,6 +41,11 @@ class LeaderboardView extends PureComponent {
);
};
_renderEmptyView = () => {
const { refreshing } = this.props;
return <>{refreshing ? <ListPlaceHolder /> : <EmptyScreenView />}</>;
};
render() {
const { users, intl, fetchLeaderBoard, refreshing, selectedIndex } = this.props;
return (
@ -70,7 +76,7 @@ class LeaderboardView extends PureComponent {
refreshing={refreshing}
keyExtractor={(item) => get(item, '_id', Math.random()).toString()}
removeClippedSubviews={false}
ListEmptyComponent={<ListPlaceHolder />}
ListEmptyComponent={this._renderEmptyView}
onRefresh={() => fetchLeaderBoard()}
renderItem={this._renderItem}
contentContainerStyle={styles.listContentContainer}

View File

@ -8,6 +8,7 @@ import { parsePost } from '../../utils/postParser';
import { extractMetadata, makeJsonMetadata } from '../../utils/editor';
import { CommentHistoryItem, LatestMarketPrices, ReceivedVestingShare, Referral, ReferralStat } from './ecency.types';
import { convertCommentHistory, convertLatestQuotes, convertReferral, convertReferralStat } from './converters';
import { isArray } from 'lodash';
@ -394,7 +395,12 @@ export const getFragments = async () => {
export const getLeaderboard = async (duration:'day'|'week'|'month') => {
try{
const response = await ecencyApi.get(`private-api/leaderboard/${duration}`)
return response.data;
const rawData = response.data;
if(!rawData || !isArray(rawData)){
throw new Error('Invalid response returned');
}
return rawData;
} catch(error) {
bugsnagInstance.notify(error)
}