commons.exceptions.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. cryptolib.modules.commons = cryptolib.modules.commons || {};
  9. /**
  10. * Defines our exception wrapper.
  11. *
  12. * @param message.
  13. * The string to use in the error description.
  14. */
  15. cryptolib.modules.commons.exceptions = function(box) {
  16. 'use strict';
  17. box.commons = box.commons || {};
  18. box.commons.exceptions = {};
  19. box.commons.exceptions.CryptoLibException = function(
  20. customMessage, originalMessage) {
  21. this.customMessage = customMessage;
  22. this.originalMessage = originalMessage;
  23. };
  24. box.commons.exceptions.CryptoLibException.prototype = {
  25. /**
  26. * Returns the exception message.
  27. *
  28. * @return {string} The message.
  29. */
  30. toString: function() {
  31. var errorMessage = 'ERROR: ';
  32. if (typeof this.originalMessage !== 'undefined') {
  33. errorMessage += this.customMessage +
  34. '. Original Error Message: ' + this.originalMessage;
  35. } else {
  36. errorMessage += this.customMessage;
  37. }
  38. return errorMessage;
  39. }
  40. };
  41. };