| Total Complexity | 11 |
| Complexity/F | 1.57 |
| Lines of Code | 37 |
| Function Count | 7 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | /*eslint no-console: 0 */ |
||
| 3 | class ErrorHandler{ |
||
| 4 | constructor(api){ |
||
| 5 | this.api = api; |
||
| 6 | } |
||
| 7 | |||
| 8 | handleCatch(e){ |
||
| 9 | // If babel supported extending of Error in a correct way instanceof would be used here |
||
| 10 | if(e.name === "InvalidInputException"){ |
||
| 11 | if(this.api._options.valid !== this.api._defaults.valid){ |
||
| 12 | this.api._options.valid(false); |
||
| 13 | } |
||
| 14 | else{ |
||
| 15 | throw e.message; |
||
| 16 | } |
||
| 17 | } |
||
| 18 | else{ |
||
| 19 | throw e; |
||
| 20 | } |
||
| 21 | |||
| 22 | this.api.render = function(){}; |
||
| 23 | } |
||
| 24 | |||
| 25 | wrapBarcodeCall(func){ |
||
| 26 | try{ |
||
| 27 | var result = func(...arguments); |
||
| 28 | this.api._options.valid(true); |
||
| 29 | return result; |
||
| 30 | } |
||
| 31 | catch(e){ |
||
| 32 | this.handleCatch(e); |
||
| 33 | |||
| 34 | return this.api; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | export default ErrorHandler; |
||
| 40 |