123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- *
- * "Restricted Materials of IBM"
- *
- * 5746-SM2
- *
- * (C) Copyright IBM Corp. 2015, 2020
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore'], function (_) {
- return {
- _getResponse: function _getResponse(request) {
- var response = request.responseJSON;
- if (!response) {
- if (request.responseText && request.responseText.length > 0) {
- response = JSON.parse(request.responseText); //TODO: JSON.parse generally should have try/catch
- }
- }
- return response || {};
- },
- _getCAFCode: function _getCAFCode(response) {
- var code;
- // For some reason, caf blocks the real code. We check the code in the message itself
- var m = response.messages && response.messages[0];
- if (m && m.indexOf('CM-REQ-4032') !== -1) {
- code = 'cmEmptySelection';
- }
- return code;
- },
- showError: function showError(glassContext, request, options) {
- var response = this._getResponse(request);
- var message = void 0;
- var code = response.errorCode;
- var stringResource = glassContext.appController.currentAppView.currentContentView.services.getSvcSync('.StringResources');
- // Check if we have a nicer message in our resources.
- if (code) {
- if (code === 'caf') {
- // For some reason, caf blocks the real code. We check the code in the message itself
- code = this._getCAFCode(response) || code;
- }
- message = stringResource.get(code, _.extend({
- _: 'NOT_FOUND'
- }, options));
- }
- if (!message || message === 'NOT_FOUND') {
- message = response.messages && response.messages[0];
- }
- if (!message || message.length === 0) {
- message = stringResource.get('saveFailed');
- }
- // In case we show a dialog after the toast (e.g. saveas dialog) we want the toast to appear on top
- setTimeout(function () {
- glassContext.appController.showToast(message, {
- type: 'error',
- preventDuplicates: true
- });
- }, 10);
- return code;
- },
- getErrorCode: function getErrorCode(request) {
- var response = request.responseJSON;
- if (!response) {
- response = JSON.parse(request.responseText); //TODO: This could call getResponse
- }
- return response.errorCode;
- },
- /**
- * check is the current session user has a capability
- * it relies on the fact that .DashboardCoreService is registered
- * @param {object} api - glassContext or dashboardAPI
- * @param {boolean} capability
- */
- hasCapability: function hasCapability(api) {
- var capability = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'canUseInteractiveDashboard';
- var userProfileService = void 0;
- if (api.getCoreSvc) {
- var dashboardCoreService = api.getCoreSvc('.DashboardCoreService');
- userProfileService = dashboardCoreService.getFeature('UserProfile');
- } else {
- userProfileService = api.getFeature('UserProfile');
- }
- return userProfileService.hasCapability(capability);
- }
- };
- });
- //# sourceMappingURL=ErrorUtils.js.map
|