summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-09-29 14:18:15 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-09-29 14:18:15 +0200
commitcba0af71df514f90fcc113db6d5310faa9296a61 (patch)
tree9869384273d7011aa5e42938b46ea6eaa3aebf7e
parentbaee420d7e42c651a20c1c74fac14949726cb0a9 (diff)
downloadbank-cba0af71df514f90fcc113db6d5310faa9296a61.tar.gz
bank-cba0af71df514f90fcc113db6d5310faa9296a61.tar.bz2
bank-cba0af71df514f90fcc113db6d5310faa9296a61.zip
less granularity when managing errors (#5787)
-rw-r--r--talerbank/app/middleware.py48
-rw-r--r--talerbank/app/views.py20
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)