From 043f263b1a48f0bc96561eaa2a7ca5df2ef82169 Mon Sep 17 00:00:00 2001 From: Maciej Dziardziel Date: Fri, 11 Jan 2013 16:07:27 +0000 Subject: [PATCH 1/3] allow certain errors to handled to jsonrpc, without sending django error signal --- jsonrpc/site.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/jsonrpc/site.py b/jsonrpc/site.py index 7a4e5fd..4d44b5e 100644 --- a/jsonrpc/site.py +++ b/jsonrpc/site.py @@ -12,6 +12,10 @@ csrf_exempt = empty_dec from django.core.serializers.json import DjangoJSONEncoder +from django.conf import settings + +#allow not to log certain errors, by specyfying class names +HANDLED_ERRORS = getattr(settings, 'JSONRPC_HANDLED_ERRORS', []) NoneType = type(None) encode_kw = lambda p: dict([(str(k), v) for k, v in p.iteritems()]) @@ -172,14 +176,16 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0', json_enc status = 200 except Error, e: - signals.got_request_exception.send(sender=self.__class__, request=request) + if not e.__class__.__name__ in HANDLED_ERRORS: + signals.got_request_exception.send(sender=self.__class__, request=request) response['error'] = e.json_rpc_format if version in ('1.1', '2.0') and 'result' in response: response.pop('result') status = e.status except Exception, e: # exception missed by others - signals.got_request_exception.send(sender=self.__class__, request=request) + if not e.__class__.__name__ in HANDLED_ERRORS: + signals.got_request_exception.send(sender=self.__class__, request=request) other_error = OtherError(e) response['error'] = other_error.json_rpc_format status = other_error.status @@ -224,13 +230,15 @@ def dispatch(self, request, method='', json_encoder=None): json_rpc = dumps(response, cls=json_encoder) except Error, e: - signals.got_request_exception.send(sender=self.__class__, request=request) + if not e.__class__.__name__ in HANDLED_ERRORS: + signals.got_request_exception.send(sender=self.__class__, request=request) response['error'] = e.json_rpc_format status = e.status json_rpc = dumps(response, cls=json_encoder) except Exception, e: # exception missed by others - signals.got_request_exception.send(sender=self.__class__, request=request) + if not e.__class__.__name__ in HANDLED_ERRORS: + signals.got_request_exception.send(sender=self.__class__, request=request) other_error = OtherError(e) response['result'] = None response['error'] = other_error.json_rpc_format From 0cb214c73556f927ea28e94931585f53d339ea77 Mon Sep 17 00:00:00 2001 From: Maciej Dziardziel Date: Fri, 11 Jan 2013 18:13:53 +0000 Subject: [PATCH 2/3] do not ignore errors in requests --- jsonrpc/site.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jsonrpc/site.py b/jsonrpc/site.py index 4d44b5e..3e25402 100644 --- a/jsonrpc/site.py +++ b/jsonrpc/site.py @@ -176,16 +176,14 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0', json_enc status = 200 except Error, e: - if not e.__class__.__name__ in HANDLED_ERRORS: - signals.got_request_exception.send(sender=self.__class__, request=request) + signals.got_request_exception.send(sender=self.__class__, request=request) response['error'] = e.json_rpc_format if version in ('1.1', '2.0') and 'result' in response: response.pop('result') status = e.status except Exception, e: # exception missed by others - if not e.__class__.__name__ in HANDLED_ERRORS: - signals.got_request_exception.send(sender=self.__class__, request=request) + signals.got_request_exception.send(sender=self.__class__, request=request) other_error = OtherError(e) response['error'] = other_error.json_rpc_format status = other_error.status From c1d27e86a84301354c2c880bd82ad3376c306f08 Mon Sep 17 00:00:00 2001 From: Maciej Dziardziel Date: Mon, 14 Jan 2013 10:54:48 +0000 Subject: [PATCH 3/3] Revert "do not ignore errors in requests" This reverts commit 0cb214c73556f927ea28e94931585f53d339ea77. --- jsonrpc/site.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jsonrpc/site.py b/jsonrpc/site.py index 3e25402..4d44b5e 100644 --- a/jsonrpc/site.py +++ b/jsonrpc/site.py @@ -176,14 +176,16 @@ def response_dict(self, request, D, is_batch=False, version_hint='1.0', json_enc status = 200 except Error, e: - signals.got_request_exception.send(sender=self.__class__, request=request) + if not e.__class__.__name__ in HANDLED_ERRORS: + signals.got_request_exception.send(sender=self.__class__, request=request) response['error'] = e.json_rpc_format if version in ('1.1', '2.0') and 'result' in response: response.pop('result') status = e.status except Exception, e: # exception missed by others - signals.got_request_exception.send(sender=self.__class__, request=request) + if not e.__class__.__name__ in HANDLED_ERRORS: + signals.got_request_exception.send(sender=self.__class__, request=request) other_error = OtherError(e) response['error'] = other_error.json_rpc_format status = other_error.status