Skip to content

Allow finer control of API errors in client code (issue #43)#44

Open
eggpi wants to merge 5 commits intoalexz-enwp:masterfrom
eggpi:master
Open

Allow finer control of API errors in client code (issue #43)#44
eggpi wants to merge 5 commits intoalexz-enwp:masterfrom
eggpi:master

Conversation

@eggpi
Copy link

@eggpi eggpi commented Jan 3, 2017

How about something like this for #43? This also includes a little bit of cleanup, and I think it's ready for a first look.

I've only tested manually so far (basically following the examples in the README with different retry parameters). I think I might be able to add some unit tests later, but let me know if there are any other testing you normally do.

wikitools/api.py Outdated


retries - How many retries to allow for in case of errors (set to 0 for no
retries). If the number of attempts is exceeeded, an exception is raised:
Copy link
Collaborator

Choose a reason for hiding this comment

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

"exceeeded"

Copy link
Author

Choose a reason for hiding this comment

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

Thanks!

except Exception, e:
print 'Attempt %d (of %d) raised exception %r' % (attempt, attempts, e)
if attempt == attempts:
raise
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be more explicit?

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, what do you suggest?

error = content['error']['code']
if error == "maxlag":
lagtime = int(re.search("(\d+) seconds", content['error']['info']).group(1))
lagtime = 0.5 + float(re.search("([0-9.-]+) seconds",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this addition of "0.5" have an inline code comment? It seems non-obvious to me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, never mind. This isn't really new logic.

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.

2 participants