You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For non-JSON content, this will trigger AttributeError: 'str' object has no attribute 'get' in the APIError's __init__
The issue in our case is that sometimes network connection failures happen, in which case the response content is:
gateway error: Error: Network connection lost.
I suspect this is coming from the Supabase API gateway. Nevertheless, I think the client could handle this more gracefully by checking the content-type of the response and raising a wrapped error like in the handler for the JSONDecodeError two lines below.
The text was updated successfully, but these errors were encountered:
I think I found a way to reproduce this, as well as the root cause. In the case of a non-successful return code, the request builder will try to raise an APIError(r.json()), and it correctly handles the case where the response may not be converted to JSON, by catching JSONDecodeError in the try block.
It does not, however, handle the case where the r.json()'s return type is not a Dict[str, str], as .json() may return an integer, a float, a string, a list, or any recursive combination of those. The most common case, and I believe may be what you experienced, is when the text field of the response comes surrounded by quotes, making the response a valid JSON that's converted to a str type, which when passed to the APIError.__init__ function causes an error.
Yes, that is exactly the issue I had. I patched this locally, but would be happy if this was fixed upstream.
What would be nice is if the message that is returned would be the message field of the APIError if it is a string, instead of being put into the details field.
The error handling in at least the request builder here is not handling non-JSON errors:
postgrest-py/postgrest/_async/request_builder.py
Line 78 in 576a5b8
For non-JSON content, this will trigger
AttributeError: 'str' object has no attribute 'get'
in the APIError's__init__
The issue in our case is that sometimes network connection failures happen, in which case the response content is:
gateway error: Error: Network connection lost.
I suspect this is coming from the Supabase API gateway. Nevertheless, I think the client could handle this more gracefully by checking the content-type of the response and raising a wrapped error like in the handler for the
JSONDecodeError
two lines below.The text was updated successfully, but these errors were encountered: