From 3ec25da402f9f888223546007f838879bd7fe69b Mon Sep 17 00:00:00 2001 From: lombardofr Date: Thu, 4 Apr 2019 17:29:20 +0200 Subject: [PATCH] Bug 644 Change-Id: I490398cebf9d0fcfbd506ed33913a017e7d55d4f Signed-off-by: lombardofr --- authosm/backend.py | 1 + authosm/exceptions.py | 1 + projecthandler/middleware.py | 14 +++++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/authosm/backend.py b/authosm/backend.py index 628eb6a..b8342eb 100644 --- a/authosm/backend.py +++ b/authosm/backend.py @@ -61,3 +61,4 @@ class OsmBackend(object): return OsmUser.objects.get(pk=user_id) except OsmUser.DoesNotExist: return None + diff --git a/authosm/exceptions.py b/authosm/exceptions.py index c0b061d..e29f204 100644 --- a/authosm/exceptions.py +++ b/authosm/exceptions.py @@ -16,4 +16,5 @@ class OSMAuthException(Exception): + pass diff --git a/projecthandler/middleware.py b/projecthandler/middleware.py index 89ae94d..2389ff3 100644 --- a/projecthandler/middleware.py +++ b/projecthandler/middleware.py @@ -1,4 +1,16 @@ +from authosm.exceptions import OSMAuthException +from django.shortcuts import render +import json class OsmProjectMiddleware(object): def process_view(self, request, view_func, view_args, view_kwargs): - return None \ No newline at end of file + return None + + def process_exception(self, request, exception): + if isinstance(exception, OSMAuthException): + try: + error_message = exception.message['detail'] + except Exception as e: + print e + error_message = 'Unknown error' + return render(request, 'error.html', {'error_message': error_message, 'collapsed_sidebar': False}) \ No newline at end of file -- 2.25.1