insights-core
insights-core copied to clipboard
[WIP] Allow --retries to work with network exceptions
Signed-off-by: Mark Huth [email protected]
Check all that apply:
- [X] Have you followed the guidelines in our Contributing document, including the instructions about commit messages?
- [X] Is this PR to correct an issue?
- [ ] Is this PR an enhancement?
Complete Description of Additions/Changes:
This is an idea to fix https://bugzilla.redhat.com/show_bug.cgi?id=2117686
The insights-core connection.py code doesn't really handle network exceptions. Callers of the connection._http_request code just expect to see status_codes containing errors rather than handling any network exceptions. This PR catches network exceptions in the _http_request method and converts it into a requests.Response object with an error status code that can be handled further up the call stack by functions that just look at the status_code. However, rather than creating a real response object, I create a Mock Response object, because we didn't really get a response, but the functions up the call stack only really handle responses, not exceptions. And so it is with the --retries logic, it only really works with responses and status_codes.
With this in mind, rather than rewriting all this network stack stuff to raise/handle exceptions and potentially break existing functionality, I just create a fake response object for the network exception and give it a generic 502 Bad Gateway response code.
Cop out? ... indeed. Ugly? ... perhaps. Simple(r)? ... yep. Seems to work? ... seems to ...