Skip to content

Commit 6ecd79f

Browse files
authored
Merge pull request #628 from plotly/animation-error-msgs
Better error messages for (i)create_animations
2 parents 8696ee9 + 3993829 commit 6ecd79f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

plotly/plotly/plotly.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1586,15 +1586,24 @@ def create_animations(figure, filename=None, sharing='public', auto_open=True):
15861586

15871587
api_url = _api_v2.api_url('plots')
15881588
r = requests.post(api_url, auth=auth, headers=headers, json=json)
1589-
r.raise_for_status()
15901589

15911590
try:
15921591
parsed_response = r.json()
15931592
except:
15941593
parsed_response = r.content
15951594

1596-
if 'error' in r and r['error'] != '':
1597-
raise exceptions.PlotlyError(r['error'])
1595+
# raise error message
1596+
if not r.ok:
1597+
message = ''
1598+
if isinstance(parsed_response, dict):
1599+
errors = parsed_response.get('errors')
1600+
if errors and errors[-1].get('message'):
1601+
message = errors[-1]['message']
1602+
if message:
1603+
raise exceptions.PlotlyError(message)
1604+
else:
1605+
# shucks, we're stuck with a generic error...
1606+
r.raise_for_status()
15981607

15991608
if sharing == 'secret':
16001609
web_url = (parsed_response['file']['web_url'][:-1] +

0 commit comments

Comments
 (0)