I simply want to surface an Exception message as a bad response in DRF.
The Exception can come from anywhere in the request. So for example, some nested function can have:
raise Exception('Something went wrong at this particular point')
And then in my view handler, i'd simply catch the Exception and raise it:
except Exception as e:
raise e
This raises an Exception in my application, but there is no way to parse the response to get my custom message.
I can try this:
return Response(e, status=status.HTTP_400_BAD_REQUEST)
But that returns an Exception itself:
Object of type Exception is not JSON serializable
So how can I simply return my Exception message as a 400?