How to send customised response if the unauthorised credentials were provided in django rest.
class StockList(APIView):
permission_classes = [IsAuthenticated]
def get(self,request):
stocks = Stock.objects.all()
serializer = StockSerializer(stocks,many=True)
return Response({'user': serializer.data,'post': serializer.data})
def post(self):
pass
Here when I Hit url by invalid credentials i get 401 error on development server. But i want to send customised response on client using json. any suggestions are welcomed. Thank you.
You can use a custom exception handler to customized response of api exception.
Then in setting.py you have to add your custom error handler
Refs: docs