'How to return structured error from Python Cloud Functions?

Currenty my function breaks with an Exception but the client (a flutter app written in Dart using cloud_functions' package) just reports an INTERNAL` error with no details.

I read that if the server function was written in NodeJS I should use this class to report an error https://firebase.google.com/docs/reference/functions/common_providers_https.httpserror

However I cannot find a way to do that using Python. My code currently just doesn't deal with exceptions and returns 200 if all is fine

 def my_function(request):
     # do stuff
     return {"data":{}}, 200

This gives in the client

 I/flutter (22202): [firebase_functions/internal] INTERNAL


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source