From 057f737cf88e1f077fe53ffdc2bca6e0167f69dd Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Fri, 17 Sep 2021 13:40:46 -0400 Subject: [PATCH] catch errors when sending messages --- reload.json | 3 ++- requirements.txt | 2 +- uncia/functions.py | 37 +++++++++++++++++++++++-------------- uncia/manage.py | 4 ++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/reload.json b/reload.json index c936463..f99b06a 100644 --- a/reload.json +++ b/reload.json @@ -14,7 +14,8 @@ ], "ignore_files": [ "reload.py", - "test.py" + "test.py", + "manage.py" ], "log_level": "INFO" } diff --git a/requirements.txt b/requirements.txt index 4628527..8cce45a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-base&subdirectory=base -e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-password-hasher&subdirectory=hasher --e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-erver&subdirectory=http_server +-e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-server&subdirectory=http_server -e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-http-urllib-client&subdirectory=http_urllib_client -e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-sql&subdirectory=sql -e git+https://git.barkshark.xyz/izaliamae/izzylib.git@rework#egg=izzylib-templates&subdirectory=template diff --git a/uncia/functions.py b/uncia/functions.py index cbb3721..160bb02 100644 --- a/uncia/functions.py +++ b/uncia/functions.py @@ -3,6 +3,7 @@ import json from functools import wraps from izzylib import LruCache, logging from izzylib.http_urllib_client import HttpUrllibClient +from izzylib.http_urllib_client.error import MaxRetryError from . import __version__ from .config import config @@ -90,20 +91,28 @@ def get_inbox(actor): def push_message(inbox, message): with db.session as s: - response = client.request( - inbox, - body = message.to_json(), - method = 'post', - privkey = s.get.config('privkey'), - keyid = f'https://{config.host}/actor#main-key' - ) + try: + response = client.request( + inbox, + body = message.to_json(), + method = 'post', + privkey = s.get.config('privkey'), + keyid = f'https://{config.host}/actor#main-key' + ) - if response.status not in [200, 202]: - try: - body = response.dict - except: - body = response.text + if response.status not in [200, 202]: + try: + body = response.dict + except: + body = response.text - logging.debug(f'Error from {inbox}: {body}') + logging.debug(f'Error from {inbox}: {body}') - return response + return response + + ## this exception catching will be used later + except Exception as s: + pass + + except MaxRetryError: + pass diff --git a/uncia/manage.py b/uncia/manage.py index d09e024..44b09c3 100644 --- a/uncia/manage.py +++ b/uncia/manage.py @@ -161,11 +161,11 @@ python3 -m uncia.manage convert [pleroma or uncia]: def cmd_accept(self, url): - cmd_request('accept', url) + return self.cmd_request('accept', url) def cmd_reject(self, url): - cmd_request('reject', url) + return self.cmd_request('reject', url) def cmd_list(self):