From 526b3c43930cec532736b48ae39ce1d408965f73 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 21 Aug 2023 20:49:55 +0200 Subject: [PATCH] Allow type to be missing. (#652) --- changelogs/fragments/652-problem-type.yml | 2 ++ plugins/module_utils/acme/errors.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/652-problem-type.yml diff --git a/changelogs/fragments/652-problem-type.yml b/changelogs/fragments/652-problem-type.yml new file mode 100644 index 00000000..313fe639 --- /dev/null +++ b/changelogs/fragments/652-problem-type.yml @@ -0,0 +1,2 @@ +bugfixes: + - "acme_* modules - correctly handle error documents without ``type`` (https://github.com/ansible-collections/community.crypto/issues/651, https://github.com/ansible-collections/community.crypto/pull/652)." diff --git a/plugins/module_utils/acme/errors.py b/plugins/module_utils/acme/errors.py index 208a1ae4..2d25defe 100644 --- a/plugins/module_utils/acme/errors.py +++ b/plugins/module_utils/acme/errors.py @@ -21,13 +21,14 @@ def format_http_status(status_code): def format_error_problem(problem, subproblem_prefix=''): + error_type = problem.get('type', 'about:blank') # https://www.rfc-editor.org/rfc/rfc7807#section-3.1 if 'title' in problem: msg = 'Error "{title}" ({type})'.format( - type=problem['type'], + type=error_type, title=problem['title'], ) else: - msg = 'Error {type}'.format(type=problem['type']) + msg = 'Error {type}'.format(type=error_type) if 'detail' in problem: msg += ': "{detail}"'.format(detail=problem['detail']) subproblems = problem.get('subproblems')