+Utils.cleanImageDataURI = (imageString, type, id) => {
+ if (/\bbase64\b/g.test(imageString)) {
+ return imageString;
+ } else if (/<\?xml\b/g.test(imageString)) {
+ const imgStr = imageString.substring(imageString.indexOf('<?xml'));
+ return 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(imgStr);
+ } else if (/\.(svg|png|gif|jpeg|jpg)$/.test(imageString)) {
+ return '/composer/assets/logos/' + type + '/' + id + '/' + imageString;
+ // return require('../images/logos/' + imageString);
+ }
+ if(type == 'nsd' || type == 'vnfd') {
+ return require('style/img/catalog-'+type+'-default.svg');
+ }
+ return require('style/img/catalog-default.svg');
+}
+
+Utils.parseError = (error) => {
+ let displayMsg = JSON.parse(error);
+ if (displayMsg.errorMessage && displayMsg.errorMessage.body) {
+ displayMsg = displayMsg.errorMessage.body;
+ if(displayMsg['last-error'] && displayMsg['last-error']['rpc-error'] && displayMsg['last-error']['rpc-error']['error-message']) {
+ displayMsg = displayMsg['last-error']['rpc-error']['error-message'];
+ }
+ }
+ return displayMsg
+}
+
+Utils.rpcError = (rpcResult) => {
+ try {
+ let info = JSON.parse(rpcResult);
+ let rpcError = info.body || info.errorMessage.body || info.errorMessage.error;
+ if (rpcError) {
+ if (typeof rpcError === 'string') {
+ const index = rpcError.indexOf('{');
+ if (index >= 0) {
+ return JSON.parse(rpcError.substr(index));
+ }
+ } else {
+ return rpcError;
+ }
+ }
+ } catch (e) {
+ }
+ console.log('invalid rpc error: ', rpcResult);
+ return null;
+}
+