From 2322ef8736e839d62930d9b6c847ce818261c26c Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Thu, 25 Jan 2018 17:40:39 -0500 Subject: on not finding the policy return 404 and json * json of what is returned from policy-engine instead of 404 html Change-Id: I44fb7e113e23f68cac44e6ad21c1bc9b37cf3d58 Issue-ID: DCAEGEN2-249 Signed-off-by: Alex Shatov --- policyhandler/web_server.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'policyhandler/web_server.py') diff --git a/policyhandler/web_server.py b/policyhandler/web_server.py index 4a6dee2..5b3227d 100644 --- a/policyhandler/web_server.py +++ b/policyhandler/web_server.py @@ -1,6 +1,6 @@ # org.onap.dcae # ================================================================================ -# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -61,14 +61,16 @@ class _PolicyWeb(object): PolicyWeb.logger.info("%s policy_id=%s headers=%s", \ req_info, policy_id, json.dumps(cherrypy.request.headers)) - res = PolicyRest.get_latest_policy((audit, policy_id, None, None)) or {} + latest_policy = PolicyRest.get_latest_policy((audit, policy_id, None, None)) or {} - PolicyWeb.logger.info("res %s policy_id=%s res=%s", req_info, policy_id, json.dumps(res)) + PolicyWeb.logger.info("res %s policy_id=%s latest_policy=%s", + req_info, policy_id, json.dumps(latest_policy)) - success, http_status_code, response_description = audit.audit_done(result=json.dumps(res)) + success, http_status_code, _ = audit.audit_done(result=json.dumps(latest_policy)) if not success: - raise cherrypy.HTTPError(http_status_code, response_description) - return res + cherrypy.response.status = http_status_code + + return latest_policy def _get_all_policies_latest(self): """retireves all the latest policies on GET /policies_latest""" @@ -82,9 +84,10 @@ class _PolicyWeb(object): res = {"valid_policies": valid_policies, "errored_policies": errored_policies} PolicyWeb.logger.info("result %s: %s", req_info, json.dumps(res)) - success, http_status_code, response_description = audit.audit_done(result=json.dumps(res)) + success, http_status_code, _ = audit.audit_done(result=json.dumps(res)) if not success: - raise cherrypy.HTTPError(http_status_code, response_description) + cherrypy.response.status = http_status_code + return res @cherrypy.expose @@ -127,7 +130,7 @@ class _PolicyWeb(object): "property": null, "config": { "foo": "bar", - "foo_updated": "2017-10-06T16:54:31.696Z" + "foo_updated": "2018-10-06T16:54:31.696Z" }, "policyVersion": "3" }, @@ -155,9 +158,10 @@ class _PolicyWeb(object): PolicyWeb.logger.info("result %s: policy_filter=%s res=%s", \ req_info, str_policy_filter, json.dumps(res)) - success, http_status_code, response_description = audit.audit_done(result=json.dumps(res)) + success, http_status_code, _ = audit.audit_done(result=json.dumps(res)) if not success: - raise cherrypy.HTTPError(http_status_code, response_description) + cherrypy.response.status = http_status_code + return res @cherrypy.expose -- cgit 1.2.3-korg