summaryrefslogtreecommitdiff
path: root/service/pixelated/resources/__init__.py
diff options
context:
space:
mode:
authorZara Gebru <zgebru@thoughtworks.com>2016-04-08 15:42:09 +0200
committerZara Gebru <zgebru@thoughtworks.com>2016-04-08 16:24:30 +0200
commit1bdad5bcf1742b279ba0a2840aec526e4f6175a7 (patch)
treeeb7eeef42d6f2cd7ac78b0a03d45db26b991ef8f /service/pixelated/resources/__init__.py
parent22a48f48963053e8e00777e305a42d5ec012874f (diff)
Issue #431: extractes the generic handling for error callbacks in init and handles login, logout, mail and tags resources
Diffstat (limited to 'service/pixelated/resources/__init__.py')
-rw-r--r--service/pixelated/resources/__init__.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/service/pixelated/resources/__init__.py b/service/pixelated/resources/__init__.py
index 469c8bc8..77425cc5 100644
--- a/service/pixelated/resources/__init__.py
+++ b/service/pixelated/resources/__init__.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import json
+import logging
from twisted.web.http import UNAUTHORIZED
from twisted.web.resource import Resource
@@ -23,6 +24,9 @@ from twisted.web.resource import Resource
from pixelated.resources.session import IPixelatedSession
from pixelated.support import log_time
+from twisted.web.http import INTERNAL_SERVER_ERROR
+log = logging.getLogger(__name__)
+
class SetEncoder(json.JSONEncoder):
def default(self, obj):
@@ -47,7 +51,17 @@ def respond_json_deferred(entity, request, status_code=200):
request.finish()
-class BaseResource(Resource):
+class GenericDeferredErrorHandler(object):
+
+ @classmethod
+ def generic_error_handling(cls, e, request):
+ log.error(e)
+ request.setResponseCode(INTERNAL_SERVER_ERROR)
+ request.write('Something went wrong!')
+ request.finish()
+
+
+class BaseResource(Resource, GenericDeferredErrorHandler):
def __init__(self, services_factory):
Resource.__init__(self)