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' ) ;
4
3
5
4
const mockedMiddlewareAPI = {
6
- getState ( ) {
5
+ getState : function getState ( ) {
7
6
return 'test' ;
8
7
} ,
9
8
} ;
9
+
10
10
const baseError = new Error ( 'There was an error.' ) ;
11
11
12
- test ( 'Catch middleware - error case' , t => {
13
- const mockedNext = ( ) => {
12
+ function errorCase ( t ) {
13
+ function mockedNext ( ) {
14
14
throw baseError ;
15
- } ;
15
+ }
16
16
17
17
t . plan ( 3 ) ;
18
18
@@ -33,10 +33,10 @@ test('Catch middleware - error case', t => {
33
33
error . message === baseError . message ,
34
34
'it should return the expected error message'
35
35
) ;
36
- } ) ;
36
+ }
37
37
38
- test ( 'Catch middleware - success case' , t => {
39
- const mockedNext = action => action ;
38
+ function successCase ( t ) {
39
+ function mockedNext ( action ) { return action ; }
40
40
41
41
t . plan ( 1 ) ;
42
42
@@ -49,4 +49,7 @@ test('Catch middleware - success case', t => {
49
49
'TEST_ACTION' ,
50
50
'it should be the passed action'
51
51
) ;
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