src/exceptions/ErrorHandler.js   A
last analyzed

Size

Lines of Code 37

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
nc 1
dl 0
loc 37
rs 10
c 1
b 1
f 0
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A ErrorHandler.js ➔ ??? 0 3 1
1
/*eslint no-console: 0 */
2
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