Skip to content

Commit f1e600b

Browse files
committed
plotly request exception
1 parent 3ae1f6b commit f1e600b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

plotly/exceptions.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
1717
"""
18-
18+
import json
1919

2020
## Base Plotly Error ##
2121

@@ -27,6 +27,30 @@ class InputError(Exception):
2727
pass
2828

2929

30+
class PlotlyRequestError(Exception):
31+
def __init__(self, requests_exception):
32+
self.status_code = requests_exception.response.status_code
33+
self.HTTPError = requests_exception
34+
content_type = requests_exception.response.headers['content-type']
35+
if 'json' in content_type:
36+
content = requests_exception.response.content
37+
if content != '':
38+
res_payload = json.loads(requests_exception.response.content)
39+
if 'detail' in res_payload:
40+
self.message = res_payload['detail']
41+
else:
42+
self.message = ''
43+
else:
44+
self.message = ''
45+
elif content_type == 'text/plain':
46+
self.message = requests_exception.response.content
47+
else:
48+
self.message = requests_exception.message
49+
50+
def __str__(self):
51+
return self.message
52+
53+
3054
## Grid Errors ##
3155

3256
COLUMN_NOT_YET_UPLOADED_MESSAGE = (

0 commit comments

Comments
 (0)