summaryrefslogtreecommitdiff
path: root/service/pixelated/resources
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-02-05 11:21:48 +0100
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-02-05 15:26:58 +0100
commit9893a5409560e1cc7123ec42d12b49e6edd6283c (patch)
tree3933147ea994a4ea71536d0c6be084827418f56d /service/pixelated/resources
parenta471b8e494b46fd85022b2105eee50fec4f84996 (diff)
(Re-)added error handling for twisted smtp sender.
- Issue #249 - Fixed all tests with that rely on sendmail deferred.
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r--service/pixelated/resources/mails_resource.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 77a47cda..f387076b 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -1,7 +1,8 @@
import json
from pixelated.adapter.model.mail import InputMail
-from pixelated.resources import respond_json
+from pixelated.resources import respond_json, respond_json_deferred
from twisted.web.resource import Resource
+from twisted.web import server
from leap.common.events import (
register,
events_pb2 as proto
@@ -86,9 +87,20 @@ class MailsResource(Resource):
def render_POST(self, request):
content_dict = json.loads(request.content.read())
- sent_mail = self._mail_service.send_mail(content_dict)
- return respond_json(sent_mail.as_dict(), request)
+ deferred = self._mail_service.send_mail(content_dict)
+
+ def onSuccess(sent_mail):
+ data = sent_mail.as_dict()
+ respond_json_deferred(data, request)
+
+ def onError(error):
+ respond_json_deferred({'message': str(error)}, request, status_code=422)
+
+ deferred.addCallback(onSuccess)
+ deferred.addErrback(onError)
+
+ return server.NOT_DONE_YET
def render_PUT(self, request):
content_dict = json.loads(request.content.read())