mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Made better handling for redirects
This commit is contained in:
parent
c6a846fe18
commit
2dc3ec12c3
|
@ -58,6 +58,11 @@ class BadRequest(Exception):
|
|||
self.message = f"params must be either a strong or OrderedDict object, not {type(object_type)}!"
|
||||
super().__init__(self.message)
|
||||
|
||||
class ServerRedirects(Exception):
|
||||
"""When MediaWiki responds with an error"""
|
||||
def __init__(self, old_url, new_url):
|
||||
self.message = f"Wiki with script of {old_url} redirects to {new_url}!"
|
||||
super().__init__(self.message)
|
||||
|
||||
class MediaWikiError(Exception):
|
||||
"""When MediaWiki responds with an error"""
|
||||
|
|
|
@ -369,10 +369,11 @@ class Wiki:
|
|||
if 499 < request.status < 600:
|
||||
logger.warning(f"A request to {self.script_url} {params} resulted in {request.status}")
|
||||
raise ServerError
|
||||
elif request.status == 302:
|
||||
elif request.status in (301, 302):
|
||||
logger.critical(
|
||||
"Redirect detected! Either the wiki given in the script settings (wiki field) is incorrect/the wiki got removed or is giving us the false value. Please provide the real URL to the wiki, current URL redirects to {}".format(
|
||||
request.url))
|
||||
raise ServerRedirects(self.script_url, request.headers.get("Location", "unknown"))
|
||||
elif request.status in (410, 404):
|
||||
raise WikiNotFoundError(request.status)
|
||||
elif 399 < request.status < 500:
|
||||
|
@ -458,7 +459,7 @@ class Wiki:
|
|||
"rclimit": amount, "rctype": "edit|new|log|categorize", "siprop": "namespaces|general"})
|
||||
try:
|
||||
response = await self.api_request(params=params)
|
||||
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError, asyncio.TimeoutError) as e:
|
||||
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError, asyncio.TimeoutError, ServerRedirects) as e:
|
||||
logger.error("A connection error occurred while requesting {}".format(params))
|
||||
raise WikiServerError(e)
|
||||
return response
|
||||
|
|
Loading…
Reference in a new issue