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 <felix@fontein.de> * Update changelogs/fragments/9198-fail-if-slack-api-response-is-not-ok-with-error-message.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>pull/9223/head
parent
c38b474982
commit
f2dbe08d0e
|
@ -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).
|
|
@ -76,7 +76,8 @@ options:
|
||||||
message_id:
|
message_id:
|
||||||
description:
|
description:
|
||||||
- Optional. Message ID to edit, instead of posting a new message.
|
- 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)).
|
- Corresponds to C(ts) in the Slack API (U(https://api.slack.com/messaging/modifying)).
|
||||||
type: str
|
type: str
|
||||||
version_added: 1.2.0
|
version_added: 1.2.0
|
||||||
|
@ -391,6 +392,8 @@ def get_slack_message(module, token, channel, ts):
|
||||||
if info['status'] != 200:
|
if info['status'] != 200:
|
||||||
module.fail_json(msg="failed to get slack message")
|
module.fail_json(msg="failed to get slack message")
|
||||||
data = module.from_json(response.read())
|
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:
|
if len(data['messages']) < 1:
|
||||||
module.fail_json(msg="no messages matching ts: %s" % ts)
|
module.fail_json(msg="no messages matching ts: %s" % ts)
|
||||||
if len(data['messages']) > 1:
|
if len(data['messages']) > 1:
|
||||||
|
|
Loading…
Reference in New Issue