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...
})
})

Written by

Full Stack Developer, Team Leader, Independent. More from me at https://hakibenita.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store