Skip to content

Commit

Permalink
Fix sent_at KeyError (#440)
Browse files Browse the repository at this point in the history
* Improve logging

* Ensure sent_at is set in echo email
  • Loading branch information
c-w authored May 9, 2020
1 parent 6fb5fec commit b785bd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion opwen_email_server/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __call__(self, *args, **kwargs) -> Response:
try:
return self._action(*args, **kwargs)
except Exception as ex:
self.log_exception(ex, 'error in action %s', self.__class__.__name__)
self.log_exception(ex, '%s(args=%r, kwargs=%r)', self.__class__.__name__, args, kwargs)
raise ex

def _action(self, *args, **kwargs) -> Response:
Expand Down
7 changes: 7 additions & 0 deletions opwen_email_server/mailers/echo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from datetime import datetime
from typing import Callable

from opwen_email_server.utils.log import LogMixin

ECHO_ADDRESS = 'echo@bot.lokole.ca'


class EchoEmailFormatter(LogMixin):
def __init__(self, now: Callable[[], datetime] = datetime.utcnow):
self._now = now

def __call__(self, email: dict) -> dict:
email['to'] = [email['from']]
email['from'] = ECHO_ADDRESS
email['sent_at'] = self._now().strftime('%Y-%m-%d %H:%M')
return email

0 comments on commit b785bd2

Please sign in to comment.