Total Complexity | 4 |
Complexity/F | 1.33 |
Lines of Code | 17 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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 |