Skip to content

Commit

Permalink
Add some small error handling to parsing saved values
Browse files Browse the repository at this point in the history
  • Loading branch information
Leapward-Koex committed May 18, 2022
1 parent 0fbfa65 commit 416e3a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion components/BottomNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { ShowInfo } from '../models/models';
import { SettingsTab } from './SettingsTab';
import { CastSettingsTab } from './CastSettingsTab';
import { logger } from '../services/Logger';

const Tab = createMaterialBottomTabNavigator();
export const BottomNavBar = () => {
Expand Down Expand Up @@ -78,7 +79,7 @@ export const BottomNavBar = () => {
}
return [];
} catch (e) {
// error reading value
logger.error('Failed to read saved releases', JSON.stringify(e));
}
};

Expand Down
19 changes: 15 additions & 4 deletions components/DownloadTorrentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SavedShowPaths } from './settingsPageComponents/SavedShowLocationSettin
import { convert } from '../services/converter';
import { downloadedShows } from '../services/DownloadedShows';
import { downloadNotificationManger } from '../services/DownloadNotificationManager';
import { logger } from '../services/Logger';

type DownloadTorrentButtonProps = {
resolution: string;
Expand Down Expand Up @@ -70,10 +71,20 @@ export const DownloadTorrentButton = ({
};

const getStoredShowPaths = async () => {
return JSON.parse(
(await AsyncStorage.getItem(StorageKeys.ShowPaths)) ??
JSON.stringify({ shows: [] }),
) as SavedShowPaths;
try {
return JSON.parse(
(await AsyncStorage.getItem(StorageKeys.ShowPaths)) ||
JSON.stringify({ shows: [] }),
) as SavedShowPaths;
} catch (ex) {
logger.error(
'Failed to parse stored show paths',
JSON.stringify(ex),
);
return {
shows: [],
};
}
};

const downloadTorrent = async () => {
Expand Down
2 changes: 1 addition & 1 deletion components/WatchListTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const ShowDayInfo = (props: ShowDayInfoProps) => {
React.useEffect(() => {
const init = async () => {
const watchList: WatchList = JSON.parse(
(await AsyncStorage.getItem(StorageKeys.WatchList)) ??
(await AsyncStorage.getItem(StorageKeys.WatchList)) ||
'{shows: []}',
);
setShowsForCurrentDay(
Expand Down

0 comments on commit 416e3a8

Please sign in to comment.