File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919
2020from firebolt .utils .exception import (
2121 ConfigurationError ,
22+ FireboltError ,
2223 FireboltStructuredError ,
2324)
2425
@@ -171,6 +172,10 @@ def raise_error_from_response(resp: Response) -> None:
171172 resp (Response): HTTP response
172173 """
173174 to_raise = None
175+ # If error is Text - raise as is
176+ if "text/plain" in resp .headers .get ("Content-Type" , "" ):
177+ raise FireboltError (resp .text )
178+ # If error is Json - parse it and raise
174179 try :
175180 decoded = resp .json ()
176181 if "errors" in decoded and len (decoded ["errors" ]) > 0 :
@@ -186,6 +191,7 @@ def raise_error_from_response(resp: Response) -> None:
186191 raise to_raise
187192
188193 # Raise status error if no error info was found in the body
194+ # This error does not contain the response body
189195 resp .raise_for_status ()
190196
191197
Original file line number Diff line number Diff line change @@ -1505,3 +1505,26 @@ async def test_unsupported_paramstyle_raises(cursor: Cursor) -> None:
15051505 await cursor .execute ("SELECT 1" )
15061506 finally :
15071507 db .paramstyle = original_paramstyle
1508+
1509+
1510+ async def test_cursor_plaintext_error (
1511+ httpx_mock : HTTPXMock ,
1512+ cursor : Cursor ,
1513+ query_url : str ,
1514+ ):
1515+ """Test handling of plaintext error responses from the server."""
1516+ httpx_mock .add_callback (
1517+ lambda * args , ** kwargs : Response (
1518+ status_code = codes .NOT_FOUND ,
1519+ text = "Plaintext error message" ,
1520+ headers = {"Content-Type" : "text/plain" },
1521+ ),
1522+ url = query_url ,
1523+ )
1524+ with raises (FireboltError ) as excinfo :
1525+ await cursor .execute ("select * from t" )
1526+
1527+ assert cursor ._state == CursorState .ERROR
1528+ assert "Plaintext error message" in str (
1529+ excinfo .value
1530+ ), "Invalid error message for plaintext error response"
Original file line number Diff line number Diff line change @@ -1391,3 +1391,26 @@ def test_unsupported_paramstyle_raises(cursor):
13911391 cursor .execute ("SELECT 1" )
13921392 finally :
13931393 db .paramstyle = original_paramstyle
1394+
1395+
1396+ def test_cursor_plaintext_error (
1397+ httpx_mock : HTTPXMock ,
1398+ cursor : Cursor ,
1399+ query_url : str ,
1400+ ):
1401+ """Test handling of plaintext error responses from the server."""
1402+ httpx_mock .add_callback (
1403+ lambda * args , ** kwargs : Response (
1404+ status_code = codes .NOT_FOUND ,
1405+ text = "Plaintext error message" ,
1406+ headers = {"Content-Type" : "text/plain" },
1407+ ),
1408+ url = query_url ,
1409+ )
1410+ with raises (FireboltError ) as excinfo :
1411+ cursor .execute ("select * from t" )
1412+
1413+ assert cursor ._state == CursorState .ERROR
1414+ assert "Plaintext error message" in str (
1415+ excinfo .value
1416+ ), "Invalid error message for plaintext error response"
You can’t perform that action at this time.
0 commit comments