forked from PlatziDev/redux-catch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (78 loc) · 2.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var runtime =
(typeof window !== 'undefined' && regeneratorRuntime) ||
require('regenerator-runtime');
function _asyncToGenerator(fn) {
return function() {
var gen = fn.apply(this, arguments);
return new Promise(function(resolve, reject) {
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
return Promise.resolve(value).then(
function(value) {
return step('next', value);
},
function(err) {
return step('throw', err);
},
);
}
}
return step('next');
});
};
}
var errorMiddleware = function errorMiddleware(errorHandler) {
return function(store) {
return function(next) {
return (function() {
var ref = _asyncToGenerator(
runtime.mark(function _callee(action) {
return runtime.wrap(
function _callee$(_context) {
while (1) {
switch ((_context.prev = _context.next)) {
case 0:
_context.prev = 0;
_context.next = 3;
return next(action);
case 3:
return _context.abrupt('return', _context.sent);
case 6:
_context.prev = 6;
_context.t0 = _context['catch'](0);
errorHandler(
_context.t0,
store.getState,
action,
store.dispatch,
);
return _context.abrupt('return', _context.t0);
case 10:
case 'end':
return _context.stop();
}
}
},
_callee,
undefined,
[[0, 6]],
);
}),
);
return function(_x) {
return ref.apply(this, arguments);
};
})();
};
};
};
module.exports = errorMiddleware;