Skip to content
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

Throwing exceptions on 400s and 500s in _do_request #5

Merged
merged 2 commits into from
Aug 19, 2014

Conversation

Codeacious
Copy link
Contributor

This is an extension to #3. Basically, the code currently doesn't throw an exception based on the response code actually given. A good example is calling get_app- if the Marathon API returns either a 400 or 500, the response won't contain the 'app' key and the actual exception will be a KeyError occurring on line 52 of client.py when it tries to retrieve this key. That's pretty bad, as this means I can't tell when I've gotten something like this in my code:
WARNING:marathon:Got HTTP 504: {"message":"Failed to wait for future within timeout"}

This gets really ugly in the code I've written to deploy new marathon apps- I use get_app to determine whether or not the current version of an app has been deployed, and if I see a KeyError, I assume it wasn't deployed and attempt to look up old versions of it and blue-green the new app with the old ones. If I got a KeyError due to a 500, then I have no idea that the app might already be there, but currently have to assume that it isn't!

So, let's use those awesome exceptions in exceptions.py! NotFoundError looks aptly named for 400s, and I added an InternalServerError exception for 500s. They're thrown when Marathon responds with a 400 or 500, meaning it's possible for callers to know what failure actually occurred.

As an aside, scale_app might not want to squelch NotFoundErrors, as the caller probably should get an exception if the app_id was invalid.

@Codeacious
Copy link
Contributor Author

Whoops, I didn't realize that MarathonHttpError was trying to get keys from the response object's json that weren't there. I've changed it to get what it can out of the response object given.

@mbabineau
Copy link
Member

Totally agree, thanks for the patch!

mbabineau added a commit that referenced this pull request Aug 19, 2014
Throwing exceptions on 400s and 500s in _do_request
@mbabineau mbabineau merged commit dbe1d7e into thefactory:master Aug 19, 2014
solarkennedy added a commit that referenced this pull request Jul 10, 2015
Added complex app with healthchecks in the itests
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