2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import store from 'sdc-app/AppStore.js';
17 import React from 'react';
18 import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
19 import i18n from 'nfvo-utils/i18n/i18n.js';
20 import SubmitErrorResponse from 'nfvo-components/SubmitErrorResponse.jsx';
22 function showVariablesInMessage(variables, msg) {
24 variables.forEach((value, index) => {
25 value = value.replace(';', ',');
26 regex = new RegExp("'%" + (index + 1) + "'");
27 msg = msg.replace(regex, value);
32 function parseCatalogExceptionObject(responseJSON) {
35 responseJSON.requestError &&
36 responseJSON.requestError.policyException
38 title = 'Error: ' + responseJSON.requestError.policyException.messageId;
39 msg = responseJSON.requestError.policyException.text;
41 responseJSON.requestError &&
42 responseJSON.requestError.serviceException
45 'Error: ' + responseJSON.requestError.serviceException.messageId;
46 msg = responseJSON.requestError.serviceException.text;
47 let { variables } = responseJSON.requestError.serviceException;
49 msg = showVariablesInMessage(variables, msg);
51 } else if (responseJSON.uploadDataErrors) {
52 title = i18n('Error: Upload Data Error');
56 uploadDataErrors: responseJSON.uploadDataErrors
61 title = responseJSON.status;
62 msg = responseJSON.message;
64 return { title, msg };
67 var errorResponseHandler = error => {
70 errorData = parseCatalogExceptionObject(error.data);
73 title: error.statusText,
74 msg: error.responseText ? error.responseText : i18n('GENERIC_ERROR')
78 type: modalActionTypes.GLOBAL_MODAL_ERROR,
85 export default errorResponseHandler;