Skip to content

Commit

Permalink
Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimenta committed Mar 4, 2021
1 parent 85505c7 commit 84a290a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/store/index.js
Expand Up @@ -5,6 +5,7 @@ import FilesystemStorage from 'redux-persist-filesystem-storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2';
import rootReducer from '../reducers';
import { migrations, version } from './migrations';
import Logger from '../util/Logger';

const MigratedStorage = {
async getItem(key) {
Expand All @@ -24,8 +25,8 @@ const MigratedStorage = {
const res = await AsyncStorage.getItem(key);
//AsyncStorage.setItem(key, ''); // clear old storage
return res;
} catch (e) {
//Logger.log('Failed to run migration', e);
} catch (error) {
Logger.error(error, { message: 'Failed to run migration' });
}
},
setItem(key, value) {
Expand All @@ -34,8 +35,8 @@ const MigratedStorage = {
removeItem(key) {
try {
return FilesystemStorage.removeItem(key);
} catch (e) {
console.warn(e);
} catch (error) {
Logger.error(error, { message: 'Failed to remove item' });
}
}
};
Expand All @@ -45,7 +46,8 @@ const persistConfig = {
version,
storage: MigratedStorage,
stateReconciler: autoMergeLevel2, // see "Merge Process" section for details.
migrate: createMigrate(migrations, { debug: false })
migrate: createMigrate(migrations, { debug: false }),
writeFailHandler: error => Logger.error(error, { message: 'Error persisting data' }) // Log error if saving state fails
};

const pReducer = persistReducer(persistConfig, rootReducer);
Expand Down

0 comments on commit 84a290a

Please sign in to comment.