From 833e6999d72b29ad482d36a712a59def1edb160a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kierski?= Date: Tue, 12 Mar 2019 15:38:22 +0100 Subject: [PATCH] Return JSON-RPC reponse on generic Exception --- galaxy/api/errors.py | 6 ++---- galaxy/api/jsonrpc.py | 7 ++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/galaxy/api/errors.py b/galaxy/api/errors.py index 1099a16..3e1921d 100644 --- a/galaxy/api/errors.py +++ b/galaxy/api/errors.py @@ -1,8 +1,6 @@ -from galaxy.api.jsonrpc import ApplicationError +from galaxy.api.jsonrpc import ApplicationError, UnknownError -class UnknownError(ApplicationError): - def __init__(self, data=None): - super().__init__(0, "Unknown error", data) +UnknownError = UnknownError class AuthenticationRequired(ApplicationError): def __init__(self, data=None): diff --git a/galaxy/api/jsonrpc.py b/galaxy/api/jsonrpc.py index a00f72d..033c04c 100644 --- a/galaxy/api/jsonrpc.py +++ b/galaxy/api/jsonrpc.py @@ -41,6 +41,10 @@ class ApplicationError(JsonRpcError): raise ValueError("The error code in reserved range") super().__init__(code, message, data) +class UnknownError(ApplicationError): + def __init__(self, data=None): + super().__init__(0, "Unknown error", data) + Request = namedtuple("Request", ["method", "params", "id"], defaults=[{}, None]) Method = namedtuple("Method", ["callback", "internal", "sensitive_params"]) @@ -171,8 +175,9 @@ class Server(): self._send_error(request.id, MethodNotFound()) except JsonRpcError as error: self._send_error(request.id, error) - except Exception: #pylint: disable=broad-except + except Exception as e: #pylint: disable=broad-except logging.exception("Unexpected exception raised in plugin handler") + self._send_error(request.id, UnknownError(str(e))) asyncio.create_task(handle())