ErrorHandler.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  7. /*eslint no-console: 0 */
  8. var ErrorHandler = function () {
  9. function ErrorHandler(api) {
  10. _classCallCheck(this, ErrorHandler);
  11. this.api = api;
  12. }
  13. _createClass(ErrorHandler, [{
  14. key: "handleCatch",
  15. value: function handleCatch(e) {
  16. // If babel supported extending of Error in a correct way instanceof would be used here
  17. if (e.name === "InvalidInputException") {
  18. if (this.api._options.valid !== this.api._defaults.valid) {
  19. this.api._options.valid(false);
  20. } else {
  21. throw e.message;
  22. }
  23. } else {
  24. throw e;
  25. }
  26. this.api.render = function () {};
  27. }
  28. }, {
  29. key: "wrapBarcodeCall",
  30. value: function wrapBarcodeCall(func) {
  31. try {
  32. var result = func.apply(undefined, arguments);
  33. this.api._options.valid(true);
  34. return result;
  35. } catch (e) {
  36. this.handleCatch(e);
  37. return this.api;
  38. }
  39. }
  40. }]);
  41. return ErrorHandler;
  42. }();
  43. exports.default = ErrorHandler;