0001-utils-move-exception_to_text-in-conversion-35380.patch
passerelle/utils/conversion.py | ||
---|---|---|
20 | 20 |
import warnings |
21 | 21 |
from StringIO import StringIO |
22 | 22 | |
23 |
from django.utils import six |
|
24 | ||
23 | 25 |
import unidecode |
24 | 26 |
from PIL import Image |
25 | 27 | |
... | ... | |
67 | 69 | |
68 | 70 |
def to_ascii(s): |
69 | 71 |
return unidecode.unidecode(s).decode('ascii') |
72 | ||
73 | ||
74 |
def exception_to_text(e): |
|
75 |
try: |
|
76 |
return six.text_type(e) |
|
77 |
except Exception: |
|
78 |
pass |
|
79 | ||
80 |
try: |
|
81 |
r = repr(e) |
|
82 |
return six.text_type(r, errors='replace') |
|
83 |
except Exception: |
|
84 |
pass |
|
85 | ||
86 |
try: |
|
87 |
args = e.args |
|
88 |
try: |
|
89 |
content = six.text_type(repr(args)) if args != [] else '' |
|
90 |
except Exception: |
|
91 |
content = '<exception-while-rendering-args>' |
|
92 |
except AttributeError: |
|
93 |
content = '' |
|
94 |
return u'%s(%s)' % (e.__class__.__name__, content) |
passerelle/utils/jsonresponse.py | ||
---|---|---|
20 | 20 |
from requests import RequestException, HTTPError |
21 | 21 | |
22 | 22 |
from passerelle.utils import log_http_request |
23 |
from passerelle.utils.conversion import exception_to_text |
|
23 | 24 | |
24 | 25 | |
25 | 26 |
DEFAULT_DEBUG = getattr(settings, 'JSONRESPONSE_DEFAULT_DEBUG', False) |
... | ... | |
37 | 38 |
super(APIError, self).__init__(*args) |
38 | 39 | |
39 | 40 | |
40 |
def exception_to_text(e): |
|
41 |
try: |
|
42 |
return six.text_type(e) |
|
43 |
except Exception: |
|
44 |
pass |
|
45 | ||
46 |
try: |
|
47 |
return six.text_type(repr(e)) |
|
48 |
except Exception: |
|
49 |
pass |
|
50 | ||
51 |
try: |
|
52 |
args = e.args |
|
53 |
try: |
|
54 |
content = six.text_type(repr(args)) if args != [] else '' |
|
55 |
except Exception: |
|
56 |
content = '<exception-while-rendering-args>' |
|
57 |
except AttributeError: |
|
58 |
content = '' |
|
59 |
return u'%s(%s)' % (e.__class__.__name__, content) |
|
60 | ||
61 | ||
62 | 41 |
class JSONEncoder(DjangoJSONEncoder): |
63 | 42 |
def default(self, o): |
64 | 43 |
if isinstance(o, time.struct_time): |
65 |
- |