1 min readMar 5, 2019
Hey, it really depends on how you implement your endpoints. We personally, use RPC most of the time so, the implementation of the views might look like this:
@api_view('POST')
def deposit(request):
asof = timezone.now()
try:
amount = int(request.data['amount'])
except (KeyError, ValueError):
return Response({
'error': 'invalid_request',
'data': {
'amount': 'missing or invalid number.'
},
) try:
account, action = account.deposit(
uid=request.user.account.uid,
amount=amount,
deposited_by=request.user,
asof=asof,
)
except ExceedsLimit:
return Response({'error': 'exceeds_limit.', 'data': None}) except InvalidAmount:
return Response({'error': 'invalid_amount.', 'data': {'amount': amount}}) except Account.DoesNotExist:
return Response({'error': 'invalid_request.', 'data': {'account': 'does not exist'}}) return Response({
# ... whatever...
})})