mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(notify): gracefully fail notifications
Instead of allowing an exception to propogate through the framework routes, catch it and log out an error about notifications not being sent. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
d6d41cdbad
commit
36bc9ae29b
2 changed files with 42 additions and 2 deletions
|
@ -13,10 +13,12 @@ import aurweb.config
|
|||
import aurweb.db
|
||||
import aurweb.l10n
|
||||
|
||||
from aurweb import db
|
||||
from aurweb import db, logging
|
||||
from aurweb.models import (PackageBase, PackageComaintainer, PackageComment, PackageNotification, PackageRequest, RequestType,
|
||||
TUVote, User)
|
||||
|
||||
logger = logging.get_logger(__name__)
|
||||
|
||||
aur_location = aurweb.config.get('options', 'aur_location')
|
||||
|
||||
|
||||
|
@ -49,7 +51,7 @@ class Notification:
|
|||
body += '\n' + '[%d] %s' % (i + 1, ref)
|
||||
return body.rstrip()
|
||||
|
||||
def send(self):
|
||||
def _send(self) -> None:
|
||||
sendmail = aurweb.config.get('notifications', 'sendmail')
|
||||
sender = aurweb.config.get('notifications', 'sender')
|
||||
reply_to = aurweb.config.get('notifications', 'reply-to')
|
||||
|
@ -111,6 +113,14 @@ class Notification:
|
|||
server.sendmail(sender, deliver_to, msg.as_bytes())
|
||||
server.quit()
|
||||
|
||||
def send(self) -> None:
|
||||
try:
|
||||
self._send()
|
||||
except OSError as exc:
|
||||
logger.error("Unable to emit notification due to an "
|
||||
"OSError (precise exception following).")
|
||||
logger.error(str(exc))
|
||||
|
||||
|
||||
class ResetKeyNotification(Notification):
|
||||
def __init__(self, uid):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue