Skip to content

Better error messages for (i)create_animations #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2016
Merged

Conversation

Kully
Copy link
Contributor

@Kully Kully commented Dec 6, 2016

Regarding Chris' suggestion here: #584 (comment)

Haven't tested all of the ways in which a request can fail, mostly because most of the not done ones I don't know how to test (i.e. Request was Throttled, Server was Down) Yes, I said most when we're talking about 2 of the 3 on the list. 🙂

  • A File already exists with this name
  • API key wasn't correct
  • API key wasn't supplied
  • User was offline
  • Permission denied (can't save the file as private)
  • Request was throttled
  • Figure was malformed
  • Server was down

@Kully
Copy link
Contributor Author

Kully commented Dec 6, 2016

cc @chriddyp @theengineear

raise exceptions.PlotlyError(r['error'])
# raise error message
if r.ok is False:
raise exceptions.PlotlyError(parsed_response['errors'][-1]['message'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't understand why we can assume that ['errors'][-1]['message'] will exist? Certainly a 500 Internal Server Error won't have that, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this just result in a KeyError that will confound and frustrate users? BEFORE, at least we got a HEY, you got a 404! or something from r.raise_for_status().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test this out? How do I test a 500 Internal Server Error. And the whole point of me adding the message here is that the 404 or whatever was not elucidating for people: a message like A file with that filename already exists is more practical for a Plotly user

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do something like:

if not r.ok:
    message = ''
    if isinstance(parsed_response, dict):
        errors = parsed_respnonse.get('errors')
        if errors and errors[-1].get('message'):
            message = errors[-1]['message']
    if message:
        raise exceptions.PlotlyError(message)
    else:
        # shucks, we're stuck with a generic error...
        r.raise_for_status()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would parsed_response not be a dict?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

504 gateway timeouts. An HTML response gets returned instead of JSON

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if the network is down. e.g. try turning off your wifi and then making the request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that worked last time I tried in here...

Should we check if the figure is malformed though?
I tried passing a figure by changing the label data to datas (obviously wrong) and the request went through with all but a title and no plot.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we can assume that if the request is OK, the content should be predictable. Our api is supposed to remain backwards-compatible and so this shouldn't be a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'm good with this

@Kully
Copy link
Contributor Author

Kully commented Dec 7, 2016

@theengineear good to go? 💃 ?

@theengineear
Copy link
Contributor

💃 !

@Kully Kully merged commit 6ecd79f into master Dec 7, 2016
@nicolaskruchten nicolaskruchten deleted the animation-error-msgs branch June 19, 2020 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants