[api.http] handling 'too many redirects' exception

This commit is contained in:
Vinicius Moreira
2021-12-14 12:13:38 -03:00
parent 04271efebc
commit e4370bbe7a
2 changed files with 16 additions and 5 deletions

View File

@@ -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`)

View File

@@ -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)