ACME: improve error handling (#49266)

* Improve error handling: when parse_json_result is False, still return the error message.

* Remove content body from info dict.

* Add changelog.
This commit is contained in:
Felix Fontein 2018-11-29 09:00:39 +01:00 committed by René Moser
parent 829fc0feda
commit b842b1b97e
2 changed files with 6 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "ACME modules: improve error messages in some cases (include error returned by server)."

View file

@ -564,7 +564,7 @@ class ACMEAccount(object):
try: try:
content = resp.read() content = resp.read()
except AttributeError: except AttributeError:
content = info.get('body') content = info.pop('body')
if content or not parse_json_result: if content or not parse_json_result:
if (parse_json_result and info['content-type'].startswith('application/json')) or 400 <= info['status'] < 600: if (parse_json_result and info['content-type'].startswith('application/json')) or 400 <= info['status'] < 600:
@ -579,6 +579,8 @@ class ACMEAccount(object):
continue continue
if parse_json_result: if parse_json_result:
result = decoded_result result = decoded_result
else:
result = content
except ValueError: except ValueError:
raise ModuleFailException("Failed to parse the ACME response: {0} {1}".format(url, content)) raise ModuleFailException("Failed to parse the ACME response: {0} {1}".format(url, content))
else: else:
@ -608,7 +610,7 @@ class ACMEAccount(object):
try: try:
content = resp.read() content = resp.read()
except AttributeError: except AttributeError:
content = info.get('body') content = info.pop('body')
# Process result # Process result
if parse_json_result: if parse_json_result: