Commit b5e9a6d3 authored by Martin Matějek's avatar Martin Matějek

Unify failure reporting of Api operations; use exceptions

parent 1c7033ea
......@@ -9,6 +9,8 @@ from .exceptions import (
MediaTypeNotAvailableException,
NoSuchActionException,
NoSuchNotificationException,
NoSuchNotificationSkeletonException,
NotificationStorageException,
)
from .sorting import Sorting
......@@ -132,12 +134,15 @@ def process_args(parser, args):
if args.default_action:
opts['default_action'] = args.default_action
ret = api.create(**opts)
if ret:
# still work-in-progress
try:
ret = api.create(**opts)
logger.info("Succesfully created notification '%s'", format(ret))
else:
logger.error("Failed to create notification.")
except NoSuchNotificationSkeletonException:
logger.warning("'%s' is not valid notification template", args.template)
sys.exit(1)
except NotificationStorageException as e:
logger.error("Failed to create notification. Reason: %s", e)
sys.exit(1)
elif args.command == 'list':
......@@ -169,9 +174,12 @@ def process_args(parser, args):
logger.warning(e)
except MediaTypeNotAvailableException as e:
logger.warning(e)
elif args.command == 'call':
try:
api.call_action(args.msgid, args.action, args.cmd_args)
except NoSuchNotificationException as e:
logger.warning(e)
except NoSuchActionException as e:
logger.error("Failed to call action on notification: %s", e)
......
......@@ -6,7 +6,9 @@ from .exceptions import (
MediaTypeNotAvailableException,
NoSuchActionException,
NoSuchNotificationException,
NotificationNotDismissibleException
NoSuchNotificationSkeletonException,
NotificationNotDismissibleException,
NotificationStorageException,
)
from .pluginstorage import PluginStorage
from .notificationstorage import NotificationStorage
......@@ -87,7 +89,7 @@ class Api:
skel = self.plugins.get_skeleton(skel_id)
if not skel:
return None
raise NoSuchNotificationSkeletonException
notification_defaults = skel.get_skeleton_defaults()
notification_defaults.update(user_opts)
......@@ -96,7 +98,7 @@ class Api:
success = self.notifications.store(notif)
if not success:
return False
raise NotificationStorageException
return notif.notif_id
......
......@@ -18,5 +18,11 @@ class MediaTypeNotAvailableException(NotifylibError):
class NoSuchNotificationException(NotifylibError):
pass
class NoSuchNotificationSkeletonException(NotifylibError):
pass
class NotificationNotDismissibleException(NotifylibError):
pass
class NotificationStorageException(NotifylibError):
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment