File tree Expand file tree Collapse file tree 3 files changed +30
-19
lines changed Expand file tree Collapse file tree 3 files changed +30
-19
lines changed Original file line number Diff line number Diff line change 1+ function middlewareFactory ( errorHandler ) {
2+ return function middlewareStore ( store ) {
3+ return function middlewareNext ( next ) {
4+ return function middlewareAction ( action ) {
5+ try {
6+ return next ( action ) ;
7+ } catch ( error ) {
8+ errorHandler ( error , store . getState ) ;
9+ return error ;
10+ }
11+ } ;
12+ } ;
13+ } ;
14+ }
15+
16+ module . exports = middlewareFactory ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import test from 'tape' ;
2-
3- import middleware from '../build/index.js' ;
1+ const test = require ( 'tape' ) ;
2+ const middleware = require ( './index.js' ) ;
43
54const mockedMiddlewareAPI = {
6- getState ( ) {
5+ getState : function getState ( ) {
76 return 'test' ;
87 } ,
98} ;
9+
1010const baseError = new Error ( 'There was an error.' ) ;
1111
12- test ( 'Catch middleware - error case' , t => {
13- const mockedNext = ( ) => {
12+ function errorCase ( t ) {
13+ function mockedNext ( ) {
1414 throw baseError ;
15- } ;
15+ }
1616
1717 t . plan ( 3 ) ;
1818
@@ -33,10 +33,10 @@ test('Catch middleware - error case', t => {
3333 error . message === baseError . message ,
3434 'it should return the expected error message'
3535 ) ;
36- } ) ;
36+ }
3737
38- test ( 'Catch middleware - success case' , t => {
39- const mockedNext = action => action ;
38+ function successCase ( t ) {
39+ function mockedNext ( action ) { return action ; }
4040
4141 t . plan ( 1 ) ;
4242
@@ -49,4 +49,7 @@ test('Catch middleware - success case', t => {
4949 'TEST_ACTION' ,
5050 'it should be the passed action'
5151 ) ;
52- } ) ;
52+ }
53+
54+ test ( 'Catch middleware - error case' , errorCase ) ;
55+ test ( 'Catch middleware - success case' , successCase ) ;
You can’t perform that action at this time.
0 commit comments