# HG changeset patch # User Goffi # Date 1592578071 -7200 # Node ID b1215347b5c33ae536ad41ba9f7e41c9ae2d540a # Parent 0930b06f022f8b1da84df2b534971fe3c0e89e9c pages (bridge): better handling of errors: when a BridgeError is catched, set a PROXY_ERROR code, and build a JSON object from the exception. diff -r 0930b06f022f -r b1215347b5c3 libervia/pages/_bridge/page_meta.py --- a/libervia/pages/_bridge/page_meta.py Fri Jun 19 16:47:51 2020 +0200 +++ b/libervia/pages/_bridge/page_meta.py Fri Jun 19 16:47:51 2020 +0200 @@ -8,6 +8,7 @@ from twisted.web import static from sat.core.i18n import _ from sat.core.log import getLogger +from sat_frontends.bridge.bridge_frontend import BridgeException from libervia.server.constants import Const as C from libervia.server.utils import ProgressHandler @@ -52,12 +53,22 @@ ).format(profile=profile, method_data=method_data)) return self.pageError(request, C.HTTP_BAD_REQUEST) - if "profile" in kwargs: + if "profile" in kwargs or "profile_key" in kwargs: log.warning(_( '"profile" key should not be in method kwargs, hack attempt? ' "profile={profile}, method_data={method_data}" ).format(profile=profile, method_data=method_data)) return self.pageError(request, C.HTTP_BAD_REQUEST) - ret = await bridge_method(*args, **kwargs, profile=profile) + try: + ret = await bridge_method(*args, **kwargs, profile=profile) + except BridgeException as e: + request.setResponseCode(C.HTTP_PROXY_ERROR) + ret = { + "fullname": e.fullname, + "message": e.message, + "condition": e.condition, + "module": e.module, + "classname": e.classname, + } return json.dumps(ret) diff -r 0930b06f022f -r b1215347b5c3 libervia/server/constants.py --- a/libervia/server/constants.py Fri Jun 19 16:47:51 2020 +0200 +++ b/libervia/server/constants.py Fri Jun 19 16:47:51 2020 +0200 @@ -114,6 +114,7 @@ HTTP_FORBIDDEN = 403 HTTP_NOT_FOUND = 404 HTTP_INTERNAL_ERROR = 500 + HTTP_PROXY_ERROR = 502 HTTP_SERVICE_UNAVAILABLE = 503 ## Cache ##