Mercurial > libervia-web
changeset 1296:b1215347b5c3
pages (bridge): better handling of errors:
when a BridgeError is catched, set a PROXY_ERROR code, and build a JSON object from the
exception.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Jun 2020 16:47:51 +0200 |
parents | 0930b06f022f |
children | 999dccf0093e |
files | libervia/pages/_bridge/page_meta.py libervia/server/constants.py |
diffstat | 2 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)