When catching and converting exceptions, handle connection errors first #469
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some HTTP libraries (in my case, aiohttp) have exception hierarchies that themselves use multiple inheritance to make sure the specific exceptions they throw also inherit from a generic timeout exception (here: asyncio.TimeoutError). Additionally, they sometimes have bugs where they don't raise the exact exception type they should be raising in specific circumstances: see aiohttp/client.py.
What I'm proposing here is to just switch around two catch statements: in almost all cases, connection errors are either completely separate exceptions from timeout errors, or they are the more specific exception. So catching connection errors first is the safer thing to do.
This fixes a recent build failure for bravado-asyncio, where new versions of aiohttp again changed things with connection errors. We already have code to disable bravado connection error integration tests on Windows since this was an issue on that platform for quite some time already.
I've verified that this change not only fixes the recent build failure, but also makes the tests work properly on Windows.