summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorAlexandre Pretto Nunes <anunes@thoughtworks.com>2014-10-08 16:23:09 -0300
committerAlexandre Pretto Nunes <anunes@thoughtworks.com>2014-10-08 16:24:40 -0300
commitd7f522acd0b97da86522841968b05c60ee5de289 (patch)
tree4cb15f642d956bd689d45790d0f88d074b57d02d /service/pixelated
parentf4b52ce31b9aa56a9aeac7b3198c49fea6c29369 (diff)
#92 Add handling of errors when sending mail
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/user_agent.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py
index 93a3caf3..12b9a97a 100644
--- a/service/pixelated/user_agent.py
+++ b/service/pixelated/user_agent.py
@@ -66,13 +66,16 @@ def features():
@app.route('/mails', methods=['POST'])
def send_mail():
- _mail = InputMail.from_dict(request.json)
- draft_id = request.json.get('ident')
- if draft_id:
- mail_service.send(draft_id, _mail)
- else:
- _mail = mail_service.create_draft(_mail)
- return respond_json(_mail.as_dict())
+ try:
+ _mail = InputMail.from_dict(request.json)
+ draft_id = request.json.get('ident')
+ if draft_id:
+ mail_service.send(draft_id, _mail)
+ else:
+ _mail = mail_service.create_draft(_mail)
+ return respond_json(_mail.as_dict())
+ except Exception as error:
+ return respond_json({'message': '\n'.join(list(error.args))}, status_code=500)
@app.route('/mails', methods=['PUT'])