AjaxHelper.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: BI Dashboard
  6. *| (C) Copyright IBM Corp. 2018
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define([], function () {
  13. 'use strict';
  14. /**
  15. *we could pass options for initialization
  16. *@constructor
  17. */
  18. var AjaxHelper = function AjaxHelper() {
  19. return {
  20. showAjaxServiceErrorMessage: function showAjaxServiceErrorMessage(dashboardApi, jqXHR) {
  21. var messages = '';
  22. if (jqXHR) {
  23. var responseJSON = jqXHR.responseJSON;
  24. if (responseJSON) {
  25. if (responseJSON.messages) {
  26. messages = jqXHR.responseJSON.messages.join('\n');
  27. } else if (responseJSON.cause) {
  28. try {
  29. var cause = JSON.parse(responseJSON.cause);
  30. if (cause.messages) {
  31. messages = cause.messages.join('\n');
  32. }
  33. } catch (e) {
  34. //if we get here, 'cause' is not a json object
  35. messages = responseJSON.cause;
  36. }
  37. }
  38. } else {
  39. messages = jqXHR.responseText;
  40. }
  41. }
  42. if (messages && messages.length > 0) {
  43. // RTC189248 - Don't show empty error messages!
  44. dashboardApi.showErrorMessage(messages, 'Error');
  45. }
  46. }
  47. };
  48. };
  49. return new AjaxHelper();
  50. });
  51. //# sourceMappingURL=AjaxHelper.js.map