summaryrefslogtreecommitdiff
path: root/talerbank/app/middleware.py
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-04-12 15:42:37 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-04-12 15:42:37 +0200
commit088708f1418f7e1f4fba20654c31dbec3d4d072d (patch)
tree0b473cdcb75024badf6bdc46a7821cca9dc06a4a /talerbank/app/middleware.py
parent9d134d42f781d31ccbe92f734ae8c1185e9d46e9 (diff)
downloadbank-088708f1418f7e1f4fba20654c31dbec3d4d072d.tar.gz
bank-088708f1418f7e1f4fba20654c31dbec3d4d072d.tar.bz2
bank-088708f1418f7e1f4fba20654c31dbec3d4d072d.zip
No custom DoesNotExist classes anymore.
They yield different results on different systems..
Diffstat (limited to 'talerbank/app/middleware.py')
-rw-r--r--talerbank/app/middleware.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/talerbank/app/middleware.py b/talerbank/app/middleware.py
index f6f8c1e..371d9b6 100644
--- a/talerbank/app/middleware.py
+++ b/talerbank/app/middleware.py
@@ -106,10 +106,25 @@ class ExceptionMiddleware:
# Check if the endpoint should cause a human-readable
# page to be returned.
render_to = self.render.get(request.path)
+
+ try:
+ hint = exception.hint
+ http_status_code = exception.http_status_code
+ ##
+ # This exception happens when the middleware is catching
+ # DoesNotExist exceptions; the ideal fix is to get BankAccount
+ # and BankTransaction classes to override their 'DoesNotExist'
+ # field wiht some custom class, but that wasn't straightforward
+ # (in the sense that on different systems we had different
+ # results, so we fallback on this more sound / manual approach)
+ except AttributeError:
+ hint = "The database (BankAccount / BankTransaction) object wasn't found."
+ http_status_code = 404
+
if not render_to:
return JsonResponse({"ec": taler_ec,
- "error": exception.hint},
- status=exception.http_status_code)
+ "error": hint},
+ status=http_status_code)
request.session["profile_hint"] = \
True, False, exception.hint
return redirect(render_to)