mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-06 21:44:16 +02:00
[api.http] handling 'too many redirects' exception
This commit is contained in:
@@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [0.9.24]
|
||||
### Improvements
|
||||
- General
|
||||
- handling http redirect errors
|
||||
|
||||
- Web
|
||||
- able to specify a custom User-Agent when installing apps that demand specific settings to work properly on Electron 13.X (e.g: WhatsApp Web)
|
||||
- checking for javascript fixes based on the Electron version (saved on disk as `~/.local/share/bauh/web/fixes/electron_{branch}/{app_name}.js`)
|
||||
|
||||
@@ -52,7 +52,10 @@ class HttpClient:
|
||||
except Exception as e:
|
||||
if isinstance(e, requests.exceptions.ConnectionError):
|
||||
self.logger.error('Internet seems to be off')
|
||||
raise
|
||||
raise e
|
||||
elif isinstance(e, requests.exceptions.TooManyRedirects):
|
||||
self.logger.warning(f"Too many redirects for GET -> {url}")
|
||||
raise e
|
||||
|
||||
self.logger.error("Could not retrieve data from '{}'".format(url))
|
||||
traceback.print_exc()
|
||||
@@ -100,9 +103,14 @@ class HttpClient:
|
||||
|
||||
def exists(self, url: str, session: bool = True, timeout: int = 5) -> bool:
|
||||
params = {'url': url, 'allow_redirects': True, 'verify': False, 'timeout': timeout}
|
||||
if session:
|
||||
res = self.session.head(**params)
|
||||
else:
|
||||
res = self.session.get(**params)
|
||||
|
||||
try:
|
||||
if session:
|
||||
res = self.session.head(**params)
|
||||
else:
|
||||
res = self.session.get(**params)
|
||||
except requests.exceptions.TooManyRedirects:
|
||||
self.logger.warning(f"{url} seems to exist, but too many redirects have happened")
|
||||
return True
|
||||
|
||||
return res.status_code in (200, 403)
|
||||
|
||||
Reference in New Issue
Block a user