Skip to content

Commit b785bd2

Browse files
authored
Fix sent_at KeyError (#440)
* Improve logging * Ensure sent_at is set in echo email
1 parent 6fb5fec commit b785bd2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

opwen_email_server/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __call__(self, *args, **kwargs) -> Response:
3939
try:
4040
return self._action(*args, **kwargs)
4141
except Exception as ex:
42-
self.log_exception(ex, 'error in action %s', self.__class__.__name__)
42+
self.log_exception(ex, '%s(args=%r, kwargs=%r)', self.__class__.__name__, args, kwargs)
4343
raise ex
4444

4545
def _action(self, *args, **kwargs) -> Response:

opwen_email_server/mailers/echo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
from datetime import datetime
2+
from typing import Callable
3+
14
from opwen_email_server.utils.log import LogMixin
25

36
ECHO_ADDRESS = '[email protected]'
47

58

69
class EchoEmailFormatter(LogMixin):
10+
def __init__(self, now: Callable[[], datetime] = datetime.utcnow):
11+
self._now = now
12+
713
def __call__(self, email: dict) -> dict:
814
email['to'] = [email['from']]
915
email['from'] = ECHO_ADDRESS
16+
email['sent_at'] = self._now().strftime('%Y-%m-%d %H:%M')
1017
return email

0 commit comments

Comments
 (0)