From 76483c324d672f50620cc1fb3c838e03fa5f8819 Mon Sep 17 00:00:00 2001 From: lombardofr Date: Tue, 12 Mar 2019 15:39:06 +0100 Subject: [PATCH] bug 646 Change-Id: Ibd5898c58a9a5e1015b6ab350c226d0c29f3ea16 Signed-off-by: lombardofr --- lib/osm/osmclient/clientv2.py | 5 +++-- packagehandler/views.py | 22 ++++--------------- .../template/project/projectlist.html | 2 +- static/src/packagehandler/packages_list.js | 16 ++++++++++++-- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 0914fb3..2025277 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -440,9 +440,10 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r: result['error'] = False - result['data'] = Util.json_loads_byteified(r.text) + if r.status_code != requests.codes.no_content: + result['data'] = Util.json_loads_byteified(r.text) return result def vnfd_delete(self, token, id): diff --git a/packagehandler/views.py b/packagehandler/views.py index 9783348..de90737 100644 --- a/packagehandler/views.py +++ b/packagehandler/views.py @@ -93,25 +93,11 @@ def delete_package(request, package_type=None, package_id=None): log.exception(e) result = {'error': True, 'data': str(e)} - url = 'package_list.html' - descriptors = {} - try: - if package_type == 'ns': - descriptors = client.nsd_list(user.get_token()) - elif package_type == 'vnf': - descriptors = client.vnfd_list(user.get_token()) - except Exception as e: - log.exception(e) + if result['error']: + return __response_handler(request, result['data'], url=None, status=result['data']['status'] if 'status' in result['data'] else 500) + else: + return __response_handler(request, {}, url=None, status=200) - return __response_handler(request, { - 'descriptors': descriptors['data'] if descriptors and descriptors['error'] is False else [], - 'project_id': project_id, - 'project_type': 'osm', - 'package_type': package_type, - 'alert_message': { - 'success': False if result['error'] is True else True, - 'message': 'An error occurred while processing your request.' if result and result['error'] is True else "Record deleted successfully"} - }, url) @login_required def clone_package(request, package_type=None, package_id=None): diff --git a/projecthandler/template/project/projectlist.html b/projecthandler/template/project/projectlist.html index 17382e4..e8cc77a 100644 --- a/projecthandler/template/project/projectlist.html +++ b/projecthandler/template/project/projectlist.html @@ -94,7 +94,7 @@ "columns": [ { "render": function (data, type, row) { - return ''+row['name']+'' + return ''+row['name']+'' }, "targets": 0 }, diff --git a/static/src/packagehandler/packages_list.js b/static/src/packagehandler/packages_list.js index 20a2159..0eebca6 100644 --- a/static/src/packagehandler/packages_list.js +++ b/static/src/packagehandler/packages_list.js @@ -33,7 +33,13 @@ function deletePackage(package_type, package_id, package_name) { }, error: function (result) { dialog.modal('hide'); - bootbox.alert("An error occurred."); + var data = result.responseJSON; + var title = "Error " + (data && data.code ? data.code : 'unknown'); + var message = data && data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); } }); } @@ -59,7 +65,13 @@ function clonePackage(package_type, package_id) { }, error: function (result) { dialog.modal('hide'); - bootbox.alert("An error occurred."); + var data = result.responseJSON; + var title = "Error " + (data && data.code ? data.code : 'unknown'); + var message = data && data.detail ? data.detail : 'No detail available.'; + bootbox.alert({ + title: title, + message: message + }); } }); } -- 2.25.1