ErrorHandler.js 660 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*eslint no-console: 0 */
  2. class ErrorHandler{
  3. constructor(api){
  4. this.api = api;
  5. }
  6. handleCatch(e){
  7. // If babel supported extending of Error in a correct way instanceof would be used here
  8. if(e.name === "InvalidInputException"){
  9. if(this.api._options.valid !== this.api._defaults.valid){
  10. this.api._options.valid(false);
  11. }
  12. else{
  13. throw e.message;
  14. }
  15. }
  16. else{
  17. throw e;
  18. }
  19. this.api.render = function(){};
  20. }
  21. wrapBarcodeCall(func){
  22. try{
  23. var result = func(...arguments);
  24. this.api._options.valid(true);
  25. return result;
  26. }
  27. catch(e){
  28. this.handleCatch(e);
  29. return this.api;
  30. }
  31. }
  32. }
  33. export default ErrorHandler;