From f2dbe08d0e86dcbcb78bba52d9d19d5094089cbb Mon Sep 17 00:00:00 2001 From: Matthieu Bourgain Date: Mon, 2 Dec 2024 20:11:00 +0100 Subject: [PATCH] Fail if Slack API response is not OK with error message (#9198) * Fails if slack api return is not ok * add changelog * show all error * add doc * Update plugins/modules/slack.py Co-authored-by: Felix Fontein * Update changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein --- ...il-if-slack-api-response-is-not-ok-with-error-message.yml | 2 ++ plugins/modules/slack.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml diff --git a/changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml b/changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml new file mode 100644 index 0000000000..56ab25f578 --- /dev/null +++ b/changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml @@ -0,0 +1,2 @@ +bugfixes: + - slack - fail if Slack API response is not OK with error message (https://github.com/ansible-collections/community.general/pull/9198). diff --git a/plugins/modules/slack.py b/plugins/modules/slack.py index 41dd4f5dba..58893b0f42 100644 --- a/plugins/modules/slack.py +++ b/plugins/modules/slack.py @@ -76,7 +76,8 @@ options: message_id: description: - Optional. Message ID to edit, instead of posting a new message. - - If supplied O(channel) must be in form of C(C0xxxxxxx). use C({{ slack_response.channel_id }}) to get RV(ignore:channel_id) from previous task run. + - If supplied O(channel) must be in form of C(C0xxxxxxx). use C({{ slack_response.channel }}) to get RV(ignore:channel) from previous task run. + - The token needs history scope to get information on the message to edit (C(channels:history,groups:history,mpim:history,im:history)). - Corresponds to C(ts) in the Slack API (U(https://api.slack.com/messaging/modifying)). type: str version_added: 1.2.0 @@ -391,6 +392,8 @@ def get_slack_message(module, token, channel, ts): if info['status'] != 200: module.fail_json(msg="failed to get slack message") data = module.from_json(response.read()) + if data.get('ok') is False: + module.fail_json(msg="failed to get slack message: %s" % data) if len(data['messages']) < 1: module.fail_json(msg="no messages matching ts: %s" % ts) if len(data['messages']) > 1: