softvar / simplegist

Advanced python wrapper for Github Gist API
https://pypi.python.org/pypi/simplegist
MIT License
64 stars 24 forks source link

print a more useful error message #2

Closed mattvenn closed 7 years ago

mattvenn commented 8 years ago

Something changed recently with gists and a public setting of 1 no longer worked. Github returned a useful error message but this wasn't passed on me. I've changed the exception handler to return the status code and message for easier future problem solving.

Cheers, Matt

Loknar commented 8 years ago

Might be noteworthy to add more information for other newcomers seeking answers for why the following happens

ghGist.create(name='_GISTNAME', description='_ANY_DESCRIPTION', public=1, content='_CONTENT_GOES_HERE')
*** Exception: Gist not created.

By manually adding the file change proposedby @mattvenn, the exception message changes to

ghGist.create(name='_GISTNAME', description='_ANY_DESCRIPTION', public=1, content='_CONTENT_GOES_HERE')
*** Exception: Gist not created: server response was [422] {"message":"Invalid request.\n\nNo subschema in \"anyOf\" matched.\nFor 'anyOf/0', 1 is not a boolean.\n1 is not a member of [\"true\", \"false\"].\nFor 'anyOf/1', 1 is not a string.\nFor 'anyOf/2', 1 is not a null.","documentation_url":"https://developer.github.com/v3/gists/#create-a-gist"}

This enables us to easily assume that the following might work (change public from 1 to 'true')

ghGist.create(name='_GISTNAME', description='_ANY_DESCRIPTION', public='true', content='_CONTENT_GOES_HERE')
{'id': u'a2cb35e4dd3ca3098fd29337d8s658c3', 'created_at': u'2016-05-31T19:04:57Z', 'Clone-Link': u'https://gist.github.com/a2cb35e4dd3ca3098fd29337d8s658c3.git', 'Embed-Script': u'<script src="https://gist.github.com/Loknar/a2cb35e4dd3ca3098fd29337d8s658c3.js"</script>', 'Gist-Link': u'https://gist.github.com/Loknar/a2cb35e4dd3ca3098fd29337d8s658c3'}

👍 on better exception message, but I'd also advise the owner of this project to also change the docs so newcomers don't immediately fall into this "it doesn't work" pit 😸

softvar commented 8 years ago

Sure thing @mattvenn @Loknar Thanks for letting me know. Will merge this PR and update the docs sooner. 👍

feriat commented 7 years ago

@softvar , when can we expect this PR to be merged? This is super userfull for everyone! :-)

softvar commented 7 years ago

Great work @mattvenn 👍

softvar commented 7 years ago

@apetrin It's merged and can be used via upgrading your simplegist package. 1.0.1 is the latest one.