From d7f522acd0b97da86522841968b05c60ee5de289 Mon Sep 17 00:00:00 2001 From: Alexandre Pretto Nunes Date: Wed, 8 Oct 2014 16:23:09 -0300 Subject: #92 Add handling of errors when sending mail --- service/pixelated/user_agent.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'service/pixelated') 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']) -- cgit v1.2.3