jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Raise a generic ServerError if requests response is a ServerError

Raise a generic pywikibot.exceptions.ServerError if requests response
is a ServerError (error code 500-599).

Bug: T320590
Change-Id: I1a570d1d6e1452622f771d6cdf8691c7a2c8d93c
---
M pywikibot/comms/http.py
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 48f74c8..3b903f8 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -44,6 +44,7 @@
from pywikibot.backports import Tuple
from pywikibot.exceptions import (
FatalServerError,
+ ServerError,
Server414Error,
Server504Error,
)
@@ -282,12 +283,17 @@
error('An error occurred for uri ' + response.request.url)
raise response from None

+ if response.status_code == HTTPStatus.REQUEST_URI_TOO_LONG:
+ raise Server414Error('Too long GET request')
+
if response.status_code == HTTPStatus.GATEWAY_TIMEOUT:
raise Server504Error('Server {} timed out'
.format(urlparse(response.url).netloc))

- if response.status_code == HTTPStatus.REQUEST_URI_TOO_LONG:
- raise Server414Error('Too long GET request')
+ if (not response.ok
+ and response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR):
+ raise ServerError(
+ f'{response.status_code} Server Error: {response.reason}')

# TODO: shall it raise? this might break some code, TBC
# response.raise_for_status()

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I1a570d1d6e1452622f771d6cdf8691c7a2c8d93c
Gerrit-Change-Number: 842363
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged