Returning error codes from post

merge-requests/26/head
Bob Mottram 2021-10-18 11:20:57 +01:00
parent ee11752b0b
commit 1244d0fafc
2 changed files with 17 additions and 10 deletions

View File

@ -2095,10 +2095,12 @@ def threadSendPost(session, postJsonStr: str, federationList: [],
if debug:
print('Getting postJsonString for ' + inboxUrl)
try:
postResult, unauthorized = \
postResult, unauthorized, returnCode = \
postJsonString(session, postJsonStr, federationList,
inboxUrl, signatureHeaderJson,
debug)
if returnCode == 500:
break
if debug:
print('Obtained postJsonString for ' + inboxUrl +
' unauthorized: ' + str(unauthorized))
@ -2410,12 +2412,17 @@ def sendPostViaServer(signingPrivateKeyPem: str, projectVersion: str,
'Authorization': authHeader
}
postDumps = json.dumps(postJsonObject)
postResult = \
postResult, unauthorized, returnCode = \
postJsonString(session, postDumps, [],
inboxUrl, headers, debug, 5, True)
if not postResult:
if debug:
print('DEBUG: POST failed for c2s to ' + inboxUrl)
if unauthorized:
print('DEBUG: POST failed for c2s to ' +
inboxUrl + ' unathorized')
else:
print('DEBUG: POST failed for c2s to '
+ inboxUrl + ' return code ' + str(returnCode))
return 5
if debug:

View File

@ -296,7 +296,7 @@ def postJsonString(session, postJsonStr: str,
headers: {},
debug: bool,
timeoutSec: int = 30,
quiet: bool = False) -> (bool, bool):
quiet: bool = False) -> (bool, bool, int):
"""Post a json message string to the inbox of another person
The second boolean returned is true if the send is unauthorized
NOTE: Here we post a string rather than the original json so that
@ -310,18 +310,18 @@ def postJsonString(session, postJsonStr: str,
except requests.exceptions.RequestException as e:
if not quiet:
print('WARN: error during postJsonString requests ' + str(e))
return None, None
return None, None, 0
except SocketError as e:
if not quiet and e.errno == errno.ECONNRESET:
print('WARN: connection was reset during postJsonString')
if not quiet:
print('ERROR: postJsonString failed ' + inboxUrl + ' ' +
postJsonStr + ' ' + str(headers))
return None, None
return None, None, 0
except ValueError as e:
if not quiet:
print('WARN: error during postJsonString ' + str(e))
return None, None
return None, None, 0
if postResult.status_code < 200 or postResult.status_code > 202:
if postResult.status_code >= 400 and \
postResult.status_code <= 405 and \
@ -330,14 +330,14 @@ def postJsonString(session, postJsonStr: str,
print('WARN: Post to ' + inboxUrl +
' is unauthorized. Code ' +
str(postResult.status_code))
return False, True
return False, True, postResult.status_code
else:
if not quiet:
print('WARN: Failed to post to ' + inboxUrl +
' with headers ' + str(headers) +
' status code ' + str(postResult.status_code))
return False, False
return True, False
return False, False, postResult.status_code
return True, False, 0
def postImage(session, attachImageFilename: str, federationList: [],