jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/842363 )
Change subject: [IMPR] Raise a generic ServerError if requests response is a ServerError ......................................................................
[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(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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()
pywikibot-commits@lists.wikimedia.org