Improve error reporting. (#684)

pull/685/head
Felix Fontein 2023-12-08 20:57:49 +01:00 committed by GitHub
parent f12e814344
commit b5269b25a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -0,0 +1,2 @@
bugfixes:
- "acme_* modules - fix improved error reporting in case of socket errors, bad status lines, and unknown connection errors (https://github.com/ansible-collections/community.crypto/pull/684)."

View File

@ -96,12 +96,12 @@ class ACMEProtocolException(ModuleFailException):
extras['http_status'] = code extras['http_status'] = code
if code is not None and code >= 400 and content_json is not None and 'type' in content_json: if code is not None and code >= 400 and content_json is not None and 'type' in content_json:
if 'status' in content_json and content_json['status'] != code: if 'status' in content_json and content_json['status'] != code:
code = 'status {problem_code} (HTTP status: {http_code})'.format( code_msg = 'status {problem_code} (HTTP status: {http_code})'.format(
http_code=format_http_status(code), problem_code=content_json['status']) http_code=format_http_status(code), problem_code=content_json['status'])
else: else:
code = 'status {problem_code}'.format(problem_code=format_http_status(code)) code_msg = 'status {problem_code}'.format(problem_code=format_http_status(code))
if code == -1 and info.get('msg'): if code == -1 and info.get('msg'):
code += ' ({msg})'.format(msg=info['msg']) code_msg = 'error: {msg}'.format(msg=info['msg'])
subproblems = content_json.pop('subproblems', None) subproblems = content_json.pop('subproblems', None)
add_msg = ' {problem}.'.format(problem=format_error_problem(content_json)) add_msg = ' {problem}.'.format(problem=format_error_problem(content_json))
extras['problem'] = content_json extras['problem'] = content_json
@ -115,14 +115,14 @@ class ACMEProtocolException(ModuleFailException):
problem=format_error_problem(problem, subproblem_prefix='{0}.'.format(index)), problem=format_error_problem(problem, subproblem_prefix='{0}.'.format(index)),
) )
else: else:
code = 'HTTP status {code}'.format(code=format_http_status(code)) code_msg = 'HTTP status {code}'.format(code=format_http_status(code))
if code == -1 and info.get('msg'): if code == -1 and info.get('msg'):
code += ' ({msg})'.format(msg=info['msg']) code_msg = 'error: {msg}'.format(msg=info['msg'])
if content_json is not None: if content_json is not None:
add_msg = ' The JSON error result: {content}'.format(content=content_json) add_msg = ' The JSON error result: {content}'.format(content=content_json)
elif content is not None: elif content is not None:
add_msg = ' The raw error result: {content}'.format(content=to_text(content)) add_msg = ' The raw error result: {content}'.format(content=to_text(content))
msg = '{msg} for {url} with {code}'.format(msg=msg, url=url, code=format_http_status(code)) msg = '{msg} for {url} with {code}'.format(msg=msg, url=url, code=code_msg)
elif content_json is not None: elif content_json is not None:
add_msg = ' The JSON result: {content}'.format(content=content_json) add_msg = ' The JSON result: {content}'.format(content=content_json)
elif content is not None: elif content is not None: