mirror of
https://github.com/caronc/apprise.git
synced 2025-06-22 10:41:27 +02:00
Resolves error response on successful Slack post (#196)
This commit is contained in:
parent
2e6a996980
commit
384dd94b06
@ -525,25 +525,29 @@ class NotifySlack(NotifyBase):
|
|||||||
'Response Details:\r\n{}'.format(r.content))
|
'Response Details:\r\n{}'.format(r.content))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
elif attach:
|
||||||
response = loads(r.content)
|
# Attachment posts return a JSON string
|
||||||
|
try:
|
||||||
|
response = loads(r.content)
|
||||||
|
|
||||||
except (AttributeError, TypeError, ValueError):
|
except (AttributeError, TypeError, ValueError):
|
||||||
# ValueError = r.content is Unparsable
|
# ValueError = r.content is Unparsable
|
||||||
# TypeError = r.content is None
|
# TypeError = r.content is None
|
||||||
# AttributeError = r is None
|
# AttributeError = r is None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not (response and response.get('ok', True)):
|
if not (response and response.get('ok', True)):
|
||||||
# Bare minimum requirements not met
|
# Bare minimum requirements not met
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'Failed to send {}to Slack: error={}.'.format(
|
'Failed to send {}to Slack: error={}.'.format(
|
||||||
attach.name if attach else '',
|
attach.name if attach else '',
|
||||||
r.status_code))
|
r.status_code))
|
||||||
|
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
'Response Details:\r\n{}'.format(r.content))
|
'Response Details:\r\n{}'.format(r.content))
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
response = r.content
|
||||||
|
|
||||||
# Message Post Response looks like this:
|
# Message Post Response looks like this:
|
||||||
# {
|
# {
|
||||||
|
@ -116,7 +116,7 @@ def test_slack_oauth_access_token(mock_post):
|
|||||||
request.content = '{'
|
request.content = '{'
|
||||||
|
|
||||||
# As a result, we'll fail to send our notification
|
# As a result, we'll fail to send our notification
|
||||||
assert obj.send(body="test") is False
|
assert obj.send(body="test", attach=attach) is False
|
||||||
|
|
||||||
request.content = dumps({
|
request.content = dumps({
|
||||||
'ok': False,
|
'ok': False,
|
||||||
@ -125,7 +125,7 @@ def test_slack_oauth_access_token(mock_post):
|
|||||||
|
|
||||||
# A response from Slack (even with a 200 response) still
|
# A response from Slack (even with a 200 response) still
|
||||||
# results in a failure:
|
# results in a failure:
|
||||||
assert obj.send(body="test") is False
|
assert obj.send(body="test", attach=attach) is False
|
||||||
|
|
||||||
# Handle exceptions reading our attachment from disk (should it happen)
|
# Handle exceptions reading our attachment from disk (should it happen)
|
||||||
mock_post.side_effect = OSError("Attachment Error")
|
mock_post.side_effect = OSError("Attachment Error")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user