gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: less granularity when m


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: less granularity when managing errors (#5787)
Date: Sun, 29 Sep 2019 14:18:57 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new cba0af7  less granularity when managing errors (#5787)
cba0af7 is described below

commit cba0af71df514f90fcc113db6d5310faa9296a61
Author: Marcello Stanisci <address@hidden>
AuthorDate: Sun Sep 29 14:18:15 2019 +0200

    less granularity when managing errors (#5787)
---
 talerbank/app/middleware.py | 48 ++++++++++++---------------------------------
 talerbank/app/views.py      | 20 +++++++++++++++++--
 2 files changed, 30 insertions(+), 38 deletions(-)

diff --git a/talerbank/app/middleware.py b/talerbank/app/middleware.py
index a58e0d1..234baed 100644
--- a/talerbank/app/middleware.py
+++ b/talerbank/app/middleware.py
@@ -71,38 +71,18 @@ class ExceptionMiddleware:
         # List of all the exceptions that are managed by
         # this module.
         self.excs = {
-            BankAccountDoesNotExist: 0,
-            BankTransactionDoesNotExist: 0,
-            BankTransaction.DoesNotExist: 1,
-            SameAccountException: 2,
-            DebitLimitException: 3,
-            ##
-            # FIXME: needs own error code.
-            InvalidSession: 0,
-
-            ##
-            # This one unified class kills the distinction
-            # between a parameter being missing or malformed.
-            # It simplifies the error handling though, and
-            # MUST be reflected in taler_error_codes.h!
-            URLParamValidationError: 9,
-            JSONFieldException: 6,
-            CurrencyMismatch: 11,
+            BankAccountDoesNotExist: 5110,
+            BankTransactionDoesNotExist: 5111,
+            SameAccountException: 5102,
+            URLParamValidationError: 5105,
+            JSONFieldException: 5106,
+            CurrencyMismatch: 5104,
             BadFormatAmount: 11,
-            LoginFailed: 12,
-            RejectNoRightsException: 13,
-            NumberTooBig: 1,
-            NegativeNumber: 0
-        }
-
-        # List of all the HTTP endpoint that are likely
-        # to generate exceptions.
-        self.apis = {
-            "/withdraw": 5400,
-            "/taler/withdraw": 5500,
-            "/reject": 5300,
-            "/history": 5200,
-            "/admin/add/incoming": 5100
+            LoginFailed: 5312,
+            NumberTooBig: 5108,
+            NegativeNumber: 5107,
+            DebitLimitException: 5103,
+            RejectNoRightsException: 5200,
         }
 
         # Map between endpoints and Web pages to render
@@ -149,10 +129,6 @@ class ExceptionMiddleware:
         # Managed exception.  Build response.
         taler_ec = self.excs.get(exc_class)
 
-        # The way error codes compose matches
-        # definitions found in [1].
-        taler_ec += self.apis.get(request.path, 1000)
-
         # Check if the endpoint should cause a human-readable
         # page to be returned.
         render_to = self.render.get(request.path)
@@ -160,7 +136,7 @@ class ExceptionMiddleware:
         if not render_to:
             return JsonResponse({"ec": taler_ec,
                                  "error": exception.hint},
-                                status=exception.http_status_code)
+                                 status=exception.http_status_code)
         request.session["profile_hint"] = \
             True, False, exception.hint
         return redirect(render_to)
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 4adfb7d..6a7ae6d 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -366,14 +366,29 @@ def internal_register(request):
 
     # Registration goes through.
     with transaction.atomic():
-        user = User.objects.create_user(username=username, password=password)
+        user = User.objects.create_user(
+            username=username,
+            password=password)
         user_account = BankAccount(user=user)
         user_account.save()
     bank_internal_account = BankAccount.objects.get(account_no=1)
+
+    # Raise:
+    #
+    #  SameAccountException
+    #  DebitLimitException
+    #  CurrencyMismatch
+    #
+    #  Amount group:
+    #    BadFormatAmount
+    #    NumberTooBig
+    #    NegativeNumber
     wire_transfer(
-        Amount(settings.TALER_CURRENCY, 100, 0), bank_internal_account,
+        Amount(settings.TALER_CURRENCY, 100, 0),
+        bank_internal_account,
         user_account, "Joining bonus"
     )
+
     return user
 
 
@@ -1092,6 +1107,7 @@ def wire_transfer(amount, debit_account, credit_account, 
subject):
         debit_account=debit_account,
         subject=subject
     )
+
     if debit_account.debit:
         debit_account.amount.add(amount)
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]