diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2019-04-12 15:42:37 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2019-04-12 15:42:37 +0200 |
commit | 088708f1418f7e1f4fba20654c31dbec3d4d072d (patch) | |
tree | 0b473cdcb75024badf6bdc46a7821cca9dc06a4a | |
parent | 9d134d42f781d31ccbe92f734ae8c1185e9d46e9 (diff) | |
download | bank-088708f1418f7e1f4fba20654c31dbec3d4d072d.tar.gz bank-088708f1418f7e1f4fba20654c31dbec3d4d072d.tar.bz2 bank-088708f1418f7e1f4fba20654c31dbec3d4d072d.zip |
No custom DoesNotExist classes anymore.
They yield different results on different systems..
-rw-r--r-- | talerbank/app/middleware.py | 19 | ||||
-rw-r--r-- | talerbank/app/models.py | 20 |
2 files changed, 17 insertions, 22 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) diff --git a/talerbank/app/models.py b/talerbank/app/models.py index 369a84c..e617aba 100644 --- a/talerbank/app/models.py +++ b/talerbank/app/models.py @@ -121,24 +121,6 @@ class AmountField(models.Field): raise ValidationError( "Invalid input for an amount string: %s" % value) - -## -# Exception class to raise when a non-existent bank account is -# tried to be referenced. -class BankAccountDoesNotExist(ObjectDoesNotExist): - hint = "Specified bank account does not exist" - http_status_code = 404 - - -## -# Exception class to raise when a non-existent bank transaction is -# tried to be referenced. -class BankTransactionDoesNotExist(ObjectDoesNotExist): - hint = "Specified bank transaction does not exist" - http_status_code = 404 - - - ## # The class representing a bank account. class BankAccount(models.Model): @@ -147,8 +129,6 @@ class BankAccount(models.Model): account_no = models.AutoField(primary_key=True) user = models.OneToOneField(User, on_delete=models.CASCADE) amount = AmountField(default=get_zero_amount) - DoesNotExist = BankAccountDoesNotExist - ## # The class representing a bank transaction. |