0001-jsonresponse-use-string-conversion-on-exceptions-fix.patch
passerelle/utils/jsonresponse.py | ||
---|---|---|
2 | 2 |
# django-jsonresponse (https://github.com/jjay/django-jsonresponse) distributed |
3 | 3 |
# under BSD license |
4 | 4 | |
5 |
import six |
|
5 | 6 |
import datetime |
6 | 7 |
import json |
7 | 8 |
import functools |
... | ... | |
33 | 34 |
super(APIError, self).__init__(*args) |
34 | 35 | |
35 | 36 | |
37 |
def exception_to_text(e): |
|
38 |
try: |
|
39 |
return six.text_type(e) |
|
40 |
except Exception: |
|
41 |
pass |
|
42 | ||
43 |
try: |
|
44 |
return six.text_type(repr(e)) |
|
45 |
except Exception: |
|
46 |
pass |
|
47 | ||
48 |
try: |
|
49 |
content = six.text_type(repr(e.args)) if e.args != [] else '' |
|
50 |
except Exception: |
|
51 |
content = '<exception>' |
|
52 |
return u'%s(%s)' % (e.__class__.__name__, content) |
|
53 | ||
54 | ||
36 | 55 |
class JSONEncoder(DjangoJSONEncoder): |
37 | 56 |
def default(self, o): |
38 | 57 |
if isinstance(o, time.struct_time): |
... | ... | |
125 | 144 |
data = self.obj_to_response(req, resp) |
126 | 145 |
status = 200 |
127 | 146 |
except Exception as e: |
128 |
extras = {'method': req.method, 'exception': repr(e)}
|
|
147 |
extras = {'method': req.method, 'exception': exception_to_text(e)}
|
|
129 | 148 |
if not self.logger: |
130 | 149 |
extras['request'] = req |
131 | 150 |
if req.method == 'POST': |
132 |
- |