summaryrefslogtreecommitdiff
path: root/service/pixelated/resources
diff options
context:
space:
mode:
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)