Skip to content

Commit fdb5407

Browse files
committed
Catch reducer errors
1 parent eb883e1 commit fdb5407

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/browser/extension/background/messaging.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function messaging(request, sender, sendResponse) {
3838
return true;
3939
}
4040
if (request.type === 'ERROR') {
41-
if (catchedErrors.last) return true;
4241
chrome.notifications.create('app-error', {
4342
type: 'basic',
4443
title: 'An error occurred in the app',

src/browser/extension/inject/pageScript.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ window.devToolsExtension = function(next) {
88
let shouldSerialize = false;
99
let shouldInit = true;
1010
let actionsCount = 0;
11+
let errorOccurred = false;
1112

1213
function relay(type, state, action, nextActionId) {
1314
const message = {
@@ -80,10 +81,11 @@ window.devToolsExtension = function(next) {
8081
setTimeout(() => {
8182
if (action.type === 'PERFORM_ACTION') {
8283
actionsCount++;
83-
if (isLimit() || isFiltered(action.action)) return state;
84+
if (isLimit() || isFiltered(action.action) || errorOccurred) return state;
8485
relay('ACTION', store.getState(), action, actionsCount);
8586
} else {
8687
let liftedState = store.liftedStore.getState();
88+
if (errorOccurred && !liftedState.computedStates[liftedState.currentStateIndex].error) errorOccurred = false;
8789
addFilter(liftedState);
8890
relay('STATE', liftedState);
8991
actionsCount = liftedState.nextActionId;
@@ -95,7 +97,7 @@ window.devToolsExtension = function(next) {
9597

9698
function init() {
9799
window.addEventListener('message', onMessage, false);
98-
window.devToolsExtension.notifyErrors();
100+
window.devToolsExtension.notifyErrors(store, relay, () => { errorOccurred = true; });
99101
}
100102

101103
if (next) {
@@ -125,9 +127,17 @@ window.devToolsExtension.open = function(position) {
125127
}, '*');
126128
};
127129

128-
// Catch non-reducer errors
129-
window.devToolsExtension.notifyErrors = function() {
130+
// Catch errors
131+
window.devToolsExtension.notifyErrors = function(store, relay, onError) {
130132
function postError(message) {
133+
if (store && store.liftedStore && relay) {
134+
const state = store.liftedStore.getState();
135+
if (state.computedStates[state.currentStateIndex].error) {
136+
relay('STATE', state);
137+
if (onError) onError();
138+
return;
139+
}
140+
}
131141
window.postMessage({
132142
source: 'redux-page',
133143
type: 'ERROR',

0 commit comments

Comments
 (0)