summaryrefslogtreecommitdiff
path: root/service/pixelated/resources
diff options
context:
space:
mode:
authorDuda Dornelles <ddornell@thoughtworks.com>2015-02-18 13:40:41 -0200
committerDuda Dornelles <ddornell@thoughtworks.com>2015-02-18 13:40:49 -0200
commitdd63db87fdbb9667c1027edd700b4047b6983d1f (patch)
tree85c7a2875f535412760dc7d87c7550777f265814 /service/pixelated/resources
parent4a8217744e1d1ca60d158c3497a09b92f857a7fd (diff)
#294 - not failing service startup if smtp fails to start
Diffstat (limited to 'service/pixelated/resources')
-rw-r--r--service/pixelated/resources/__init__.py5
-rw-r--r--service/pixelated/resources/mails_resource.py6
2 files changed, 7 insertions, 4 deletions
diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py
index a2e4c9d4..b244900a 100644
--- a/service/pixelated/resources/__init__.py
+++ b/service/pixelated/resources/__init__.py
@@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
+import json
+
def respond_json(entity, request, status_code=200):
json_response = json.dumps(entity)
@@ -28,6 +30,3 @@ def respond_json_deferred(entity, request, status_code=200):
request.code = status_code
request.write(json_response)
request.finish()
-
-
-import json
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index f387076b..c057031a 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -1,4 +1,5 @@
import json
+from pixelated.adapter.services.mail_sender import SMTPDownException
from pixelated.adapter.model.mail import InputMail
from pixelated.resources import respond_json, respond_json_deferred
from twisted.web.resource import Resource
@@ -95,7 +96,10 @@ class MailsResource(Resource):
respond_json_deferred(data, request)
def onError(error):
- respond_json_deferred({'message': str(error)}, request, status_code=422)
+ if isinstance(error.value, SMTPDownException):
+ respond_json_deferred({'message': str(error.value)}, request, status_code=503)
+ else:
+ respond_json_deferred({'message': str(error)}, request, status_code=422)
deferred.addCallback(onSuccess)
deferred.addErrback(onError)