diff --git a/slixfeed/action.py b/slixfeed/action.py index 1b5e0f8..a1db426 100644 --- a/slixfeed/action.py +++ b/slixfeed/action.py @@ -770,11 +770,11 @@ async def add_feed(self, jid_bare, db_file, url): while True: exist = sqlite.get_feed_id_and_name(db_file, url) if not exist: - status_code = None result = await fetch.http(url) + message = result['message'] + status_code = result['status_code'] if not result['error']: document = result['content'] - status_code = result['status_code'] feed = parse(document) # if is_feed(url, feed): if is_feed(feed): @@ -880,7 +880,7 @@ async def add_feed(self, jid_bare, db_file, url): 'name' : None, 'code' : status_code, 'error' : True, - 'message': result['message'], + 'message': message, 'exist' : False} break elif isinstance(result, list): @@ -896,18 +896,19 @@ async def add_feed(self, jid_bare, db_file, url): 'name' : None, 'code' : status_code, 'error' : True, - 'message': result['message'], + 'message': message, 'exist' : False} break else: ix = exist[0] name = exist[1] + message = 'URL already exist.' result_final = {'link' : url, 'index' : ix, 'name' : name, 'code' : None, 'error' : False, - 'message': result['message'], + 'message': message, 'exist' : True} break return result_final diff --git a/slixfeed/fetch.py b/slixfeed/fetch.py index 9e07319..f0ff0dc 100644 --- a/slixfeed/fetch.py +++ b/slixfeed/fetch.py @@ -123,7 +123,7 @@ async def http(url): or 'Slixfeed/0.1') headers = {'User-Agent': user_agent} proxy = (config.get_values('settings.toml', 'network')['http_proxy'] - or '') + or None) timeout = ClientTimeout(total=10) async with ClientSession(headers=headers) as session: # async with ClientSession(trust_env=True) as session: @@ -159,18 +159,18 @@ async def http(url): 'response_url': response.url} except ClientError as e: result = {'error': True, - 'message': 'Error:' + str(e), + 'message': 'Error:' + str(e) if e else 'ClientError', 'original_url': url, 'status_code': None} except TimeoutError as e: result = {'error': True, - 'message': 'Timeout:' + str(e), + 'message': 'Timeout:' + str(e) if e else 'TimeoutError', 'original_url': url, 'status_code': None} except Exception as e: logging.error(e) result = {'error': True, - 'message': 'Error:' + str(e), + 'message': 'Error:' + str(e) if e else 'Error', 'original_url': url, 'status_code': None} return result diff --git a/slixfeed/version.py b/slixfeed/version.py index 85332e7..d0d929c 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.42' -__version_info__ = (0, 1, 42) +__version__ = '0.1.43' +__version_info__ = (0, 1, 43) diff --git a/slixfeed/xmpp/client.py b/slixfeed/xmpp/client.py index 5493ecb..20edea2 100644 --- a/slixfeed/xmpp/client.py +++ b/slixfeed/xmpp/client.py @@ -1250,8 +1250,9 @@ class Slixfeed(slixmpp.ClientXMPP): session['payload'] = form # session['prev'] = self._handle_subscription_add elif result['error']: - response = ('Failed to load URL <{}> Reason: {}' - .format(url, result['code'])) + response = ('Failed to load URL <{}> Reason: {} ' + '(status code: {})' + .format(url, result['message'], result['code'])) session['allow_prev'] = True session['next'] = None session['notes'] = [['error', response]] diff --git a/slixfeed/xmpp/component.py b/slixfeed/xmpp/component.py index 0bf8f8c..19ca3d3 100644 --- a/slixfeed/xmpp/component.py +++ b/slixfeed/xmpp/component.py @@ -1210,8 +1210,9 @@ class SlixfeedComponent(slixmpp.ComponentXMPP): session['payload'] = form # session['prev'] = self._handle_subscription_add elif result['error']: - response = ('Failed to load URL <{}> Reason: {}' - .format(url, result['code'])) + response = ('Failed to load URL <{}> Reason: {} ' + '(status code: {})' + .format(url, result['message'], result['code'])) session['allow_prev'] = True session['next'] = None session['notes'] = [['error', response]]