Skip to content

Commit

Permalink
RN-523 Added a try-catch when cleaning up state following a rehydrate (
Browse files Browse the repository at this point in the history
  • Loading branch information
hmhealey authored and enahum committed Jan 10, 2018
1 parent 87cb6d6 commit 6b8c361
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/store/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import DeviceInfo from 'react-native-device-info';
import {ViewTypes} from 'app/constants';
import initialState from 'app/initial_state';

export function messageRetention() {
import {
captureException,
LOGGER_JAVASCRIPT_WARNING
} from 'app/utils/sentry';

export function messageRetention(store) {
return (next) => (action) => {
if (action.type === 'persist/REHYDRATE') {
const {app} = action.payload;
Expand All @@ -23,7 +28,17 @@ export function messageRetention() {

// Keep only the last 60 messages for the last 5 viewed channels in each team
// and apply data retention on those posts if applies
return next(cleanupState(action));
let nextAction;
try {
nextAction = cleanupState(action);
} catch (e) {
// Sometimes, the payload is incomplete so log the error to Sentry and skip the cleanup
console.warn(e); // eslint-disable-line no-console
captureException(e, LOGGER_JAVASCRIPT_WARNING, store);
nextAction = action;
}

return next(nextAction);
} else if (action.type === ViewTypes.DATA_CLEANUP) {
const nextAction = cleanupState(action, true);
return next(nextAction);
Expand Down
1 change: 1 addition & 0 deletions app/utils/sentry/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {getCurrentTeam, getCurrentTeamMembership} from 'mattermost-redux/selecto
import {getCurrentChannel, getMyCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels';

export const LOGGER_JAVASCRIPT = 'javascript';
export const LOGGER_JAVASCRIPT_WARNING = 'javascript_warning';
export const LOGGER_NATIVE = 'native';
export const LOGGER_REDUX = 'redux';

Expand Down

0 comments on commit 6b8c361

Please sign in to comment.