ckeditorerror.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module utils/ckeditorerror
  7. */
  8. /**
  9. * The CKEditor error class.
  10. *
  11. * All errors will be shortened during the minification process in order to reduce the code size.
  12. * Therefore, all error messages should be documented in the same way as those in {@link module:utils/log}.
  13. *
  14. * Read more in the {@link module:utils/log} module.
  15. *
  16. * @extends Error
  17. */
  18. export default class CKEditorError extends Error {
  19. /**
  20. * Creates an instance of the CKEditorError class.
  21. *
  22. * Read more about error logging in the {@link module:utils/log} module.
  23. *
  24. * @param {String} message The error message in an `error-name: Error message.` format.
  25. * During the minification process the "Error message" part will be removed to limit the code size
  26. * and a link to this error documentation will be added to the `message`.
  27. * @param {Object} [data] Additional data describing the error. A stringified version of this object
  28. * will be appended to the error message, so the data are quickly visible in the console. The original
  29. * data object will also be later available under the {@link #data} property.
  30. */
  31. constructor( message, data ) {
  32. if ( data ) {
  33. message += ' ' + JSON.stringify( data );
  34. }
  35. super( message );
  36. /**
  37. * @member {String}
  38. */
  39. this.name = 'CKEditorError';
  40. /**
  41. * The additional error data passed to the constructor.
  42. *
  43. * @member {Object}
  44. */
  45. this.data = data;
  46. }
  47. /**
  48. * Checks if error is an instance of CKEditorError class.
  49. *
  50. * @param {Object} error Object to check.
  51. * @returns {Boolean}
  52. */
  53. static isCKEditorError( error ) {
  54. return error instanceof CKEditorError;
  55. }
  56. }