2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 import store from 'sdc-app/AppStore.js';
22 import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
24 function showVariablesInMessage(variables, msg) {
26 variables.forEach((value, index) => {
27 value = value.replace(';', ',');
28 regex = new RegExp('\'\%' + (index + 1) + '\'');
29 msg = msg.replace(regex, value);
34 function parseATTExceptionObject(responseJSON) {
36 if (responseJSON.requestError && responseJSON.requestError.policyException) {
37 title = 'Error: ' + responseJSON.requestError.policyException.messageId;
38 msg = responseJSON.requestError.policyException.text;
40 else if (responseJSON.requestError && responseJSON.requestError.serviceException) {
41 title = 'Error: ' + responseJSON.requestError.serviceException.messageId;
42 msg = responseJSON.requestError.serviceException.text;
43 let {variables} = responseJSON.requestError.serviceException;
45 msg = showVariablesInMessage(variables, msg);
49 title = responseJSON.status;
50 msg = responseJSON.message;
55 var errorResponseHandler = (xhr/*, textStatus, errorThrown*/) => {
57 if (xhr.responseJSON) {
58 errorData = parseATTExceptionObject(xhr.responseJSON);
62 title: xhr.statusText,
67 type: NotificationConstants.NOTIFY_ERROR,
72 export default errorResponseHandler;