424 error code returned if one or more notifications fail (#12)

This commit is contained in:
Chris Caron
2020-03-17 12:08:06 -04:00
committed by GitHub
parent 3b870c07e3
commit df04dfb3ec
3 changed files with 88 additions and 2 deletions

View File

@ -80,6 +80,7 @@ class ResponseCode(object):
bad_request = 400
not_found = 404
method_not_allowed = 405
failed_dependency = 424
internal_server_error = 500
@ -407,13 +408,20 @@ class NotifyView(View):
a_obj.add(ac_obj)
# Perform our notification at this point
a_obj.notify(
result = a_obj.notify(
content.get('body'),
title=content.get('title', ''),
notify_type=content.get('type', apprise.NotifyType.INFO),
tag=content.get('tag'),
)
if not result:
# If at least one notification couldn't be sent; change up
# the response to a 424 error code
return HttpResponse(
_('One or more notification could not be sent.'),
status=ResponseCode.failed_dependency)
except OSError:
# We could not write the temporary file to disk
return HttpResponse(
@ -488,13 +496,20 @@ class StatelessNotifyView(View):
)
# Perform our notification at this point
a_obj.notify(
result = a_obj.notify(
content.get('body'),
title=content.get('title', ''),
notify_type=content.get('type', apprise.NotifyType.INFO),
tag='all',
)
if not result:
# If at least one notification couldn't be sent; change up the
# response to a 424 error code
return HttpResponse(
_('One or more notification could not be sent.'),
status=ResponseCode.failed_dependency)
# Return our retrieved content
return HttpResponse(
_('Notification(s) sent.'),