1
hao
2025-03-27 e610e1c17f62b423a717fadaaa7b139d02857793
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
/*eslint no-console: 0 */
 
class ErrorHandler{
    constructor(api){
        this.api = api;
    }
 
    handleCatch(e){
        // If babel supported extending of Error in a correct way instanceof would be used here
        if(e.name === "InvalidInputException"){
            if(this.api._options.valid !== this.api._defaults.valid){
                this.api._options.valid(false);
            }
            else{
                throw e.message;
            }
        }
        else{
            throw e;
        }
 
        this.api.render = function(){};
    }
 
    wrapBarcodeCall(func){
        try{
            var result = func(...arguments);
            this.api._options.valid(true);
            return result;
        }
        catch(e){
            this.handleCatch(e);
 
            return this.api;
        }
    }
}
 
export default ErrorHandler;