Passed
Push — master ( 4a62f7...6ccdde )
by Zhenyu
01:23
created

src/decorators/error-handler.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 17
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 7
mnd 1
bc 1
fnc 3
dl 0
loc 17
rs 10
bpm 0.3333
cpm 1.3333
noi 0
c 0
b 0
f 0
1
import addHooks from './helpers/add-hooks';
2
3
/*
4
  a decorator to add conditional side-effect before error being thrown
5
  e.g. it can be used together with error-metrics to create conditional error-metrics
6
  e.g. it can also be used to handle specific error by throw error in the handler
7
 */
8
const errorHandler = ({ condition = () => false, handler }) =>
9
  addHooks({
10
    errorHook: (e, param, meta, context, action) => {
11
      if (condition(e)) {
12
        handler(e, param, meta, context, action);
13
      }
14
    },
15
  });
16
17
export default errorHandler;
18