jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] use response in http.error_handling_callback()

Remove some use of HttpRequest() inside http.py.

Bug: T265206
Change-Id: I5b62ff442a5df1d99bc2e656f74f9a67e25d7c6c
---
M pywikibot/comms/http.py
1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 1b97ee1..1fd2460 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -283,7 +283,7 @@
return None


-def error_handling_callback(request):
+def error_handling_callback(response):
"""
Raise exceptions and log alerts.

@@ -291,27 +291,30 @@
@type request: L{threadedhttp.HttpRequest}
"""
# TODO: do some error correcting stuff
- if isinstance(request.data, requests.exceptions.SSLError):
- if SSL_CERT_VERIFY_FAILED_MSG in str(request.data):
- raise FatalServerError(str(request.data))
+ if isinstance(response, requests.exceptions.SSLError):
+ if SSL_CERT_VERIFY_FAILED_MSG in str(response):
+ raise FatalServerError(str(response))

- if request.status_code == 504:
- raise Server504Error('Server {} timed out'
- .format(urlparse(request.url).netloc))
-
- if request.status_code == 414:
- raise Server414Error('Too long GET request')
-
- if isinstance(request.data, Exception):
+ if isinstance(response, Exception):
with suppress(Exception):
# request.data exception may contain response and request attribute
- error('An error occurred for uri ' + request.data.request.url)
- raise request.data from None
+ error('An error occurred for uri ' + response.request.url)
+ raise response from None
+
+ if response.status_code == 504:
+ raise Server504Error('Server {} timed out'
+ .format(urlparse(response.url).netloc))
+
+ if response.status_code == 414:
+ raise Server414Error('Too long GET request')
+
+ # TODO: shall it raise? this might break some code, TBC
+ # response.raise_for_status()

# HTTP status 207 is also a success status for Webdav FINDPROP,
# used by the version module.
- if request.status_code not in (200, 207):
- warning('Http response status {}'.format(request.status_code))
+ if response.status_code not in (200, 207):
+ warning('Http response status {}'.format(response.status_code))


@deprecate_arg('callback', True)
@@ -409,11 +412,12 @@
**kwargs)
except Exception as e:
request.data = e
+ response = e
else:
request.data = response

for callback in callbacks:
- callback(request)
+ callback(response)

# if there's no data in the answer we're in trouble
try:

To view, visit change 649024. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5b62ff442a5df1d99bc2e656f74f9a67e25d7c6c
Gerrit-Change-Number: 649024
Gerrit-PatchSet: 3
Gerrit-Owner: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged