mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
empty uri
This commit is contained in:
parent
f099380f72
commit
b911967168
2 changed files with 29 additions and 23 deletions
|
@ -94,20 +94,25 @@ def post_request(uri: str, body: dict | None, private_key: str, key_id: str, con
|
|||
log.activity_json=json.dumps(body)
|
||||
db.session.add(log)
|
||||
db.session.commit()
|
||||
try:
|
||||
result = HttpSignature.signed_request(uri, body, private_key, key_id, content_type, method, timeout)
|
||||
if result.status_code != 200 and result.status_code != 202:
|
||||
log.result = 'failure'
|
||||
log.exception_message += f' Response status code was {result.status_code}'
|
||||
current_app.logger.error('Response code for post attempt was ' +
|
||||
str(result.status_code) + ' ' + result.text)
|
||||
log.exception_message += uri
|
||||
if result.status_code == 202:
|
||||
log.exception_message += ' 202'
|
||||
except Exception as e:
|
||||
|
||||
if uri is None or uri == '':
|
||||
log.result = 'failure'
|
||||
log.exception_message='could not send:' + str(e)
|
||||
current_app.logger.error(f'Exception while sending post to {uri}')
|
||||
log.exception_message = 'empty uri'
|
||||
else:
|
||||
try:
|
||||
result = HttpSignature.signed_request(uri, body, private_key, key_id, content_type, method, timeout)
|
||||
if result.status_code != 200 and result.status_code != 202:
|
||||
log.result = 'failure'
|
||||
log.exception_message += f' Response status code was {result.status_code}'
|
||||
current_app.logger.error('Response code for post attempt was ' +
|
||||
str(result.status_code) + ' ' + result.text)
|
||||
log.exception_message += uri
|
||||
if result.status_code == 202:
|
||||
log.exception_message += ' 202'
|
||||
except Exception as e:
|
||||
log.result = 'failure'
|
||||
log.exception_message='could not send:' + str(e)
|
||||
current_app.logger.error(f'Exception while sending post to {uri}')
|
||||
if log.result == 'processing':
|
||||
log.result = 'success'
|
||||
db.session.commit()
|
||||
|
|
|
@ -689,16 +689,17 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload):
|
|||
community = Community.query.get(community_id)
|
||||
if community:
|
||||
instance = Instance.query.get(instance_id)
|
||||
if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'):
|
||||
instance.last_successful_send = utcnow()
|
||||
instance.failures = 0
|
||||
else:
|
||||
instance.failures += 1
|
||||
instance.most_recent_attempt = utcnow()
|
||||
instance.start_trying_again = utcnow() + timedelta(seconds=instance.failures ** 4)
|
||||
if instance.failures > 10:
|
||||
instance.dormant = True
|
||||
db.session.commit()
|
||||
if instance.inbox:
|
||||
if post_request(instance.inbox, payload, community.private_key, community.ap_profile_id + '#main-key'):
|
||||
instance.last_successful_send = utcnow()
|
||||
instance.failures = 0
|
||||
else:
|
||||
instance.failures += 1
|
||||
instance.most_recent_attempt = utcnow()
|
||||
instance.start_trying_again = utcnow() + timedelta(seconds=instance.failures ** 4)
|
||||
if instance.failures > 10:
|
||||
instance.dormant = True
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def community_in_list(community_id, community_list):
|
||||
|
|
Loading…
Add table
Reference in a new issue