From 6df9e2c2646975ffc7c312f675591870eb4b2ad8 Mon Sep 17 00:00:00 2001 From: Jefferson Stachelski Date: Fri, 25 Sep 2015 19:05:01 -0300 Subject: Issue #470 handling the update draft Deleting the new draft created if the old one was not found to fix the duplication drafts --- service/pixelated/resources/mails_resource.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'service/pixelated/resources/mails_resource.py') diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py index 75c0e14f..93a19a9b 100644 --- a/service/pixelated/resources/mails_resource.py +++ b/service/pixelated/resources/mails_resource.py @@ -166,11 +166,17 @@ class MailsResource(Resource): if draft_id: deferred_check = self._mail_service.mail_exists(draft_id) + def handleDuplicatedDraftException(error): + respond_json_deferred("", request, status_code=422) + def return422otherwise(mail_exists): if not mail_exists: respond_json_deferred("", request, status_code=422) else: - defer_response(self._draft_service.update_draft(draft_id, _mail)) + new_draft = self._draft_service.update_draft(draft_id, _mail) + new_draft.addErrback(handleDuplicatedDraftException) + defer_response(new_draft) + deferred_check.addCallback(return422otherwise) else: defer_response(self._draft_service.create_draft(_mail)) -- cgit v1.2.3