@@ -580,6 +580,13 @@ def _submit_statement(
580580 return response .json ()
581581 except requests .exceptions .HTTPError as e :
582582 if e .response is not None :
583+ # Authentication/authorization errors should raise OperationalError
584+ if e .response .status_code in (401 , 403 ):
585+ try :
586+ detail = e .response .json ().get ("detail" , str (e ))
587+ except (ValueError , json .JSONDecodeError ):
588+ detail = e .response .text or str (e )
589+ raise OperationalError (f"Authentication error: { detail } " ) from e
583590 try :
584591 detail = e .response .json ().get ("detail" , str (e ))
585592 except (ValueError , json .JSONDecodeError ):
@@ -600,8 +607,21 @@ def _get_statement_status(self, statement_handle: str) -> Dict[str, Any]:
600607 response .raise_for_status ()
601608 return response .json ()
602609 except requests .exceptions .HTTPError as e :
603- if e .response is not None and e .response .status_code == 404 :
604- raise ProgrammingError ("Statement not found" ) from e
610+ if e .response is not None :
611+ # Authentication/authorization errors should raise OperationalError
612+ if e .response .status_code in (401 , 403 ):
613+ try :
614+ detail = e .response .json ().get ("detail" , str (e ))
615+ except (ValueError , json .JSONDecodeError ):
616+ detail = e .response .text or str (e )
617+ raise OperationalError (f"Authentication error: { detail } " ) from e
618+ if e .response .status_code == 404 :
619+ raise ProgrammingError ("Statement not found" ) from e
620+ try :
621+ detail = e .response .json ().get ("detail" , str (e ))
622+ except (ValueError , json .JSONDecodeError ):
623+ detail = e .response .text or str (e )
624+ raise DatabaseError (f"HTTP error: { detail } " ) from e
605625 raise DatabaseError (f"HTTP error: { e } " ) from e
606626 except requests .exceptions .RequestException as e :
607627 raise OperationalError (f"Connection error: { e } " ) from e
@@ -647,6 +667,16 @@ def _get_statement_results(
647667 result = {"data" : rows , "columns" : [{"name" : col } for col in (columns or [])]}
648668
649669 return result
670+ except requests .exceptions .HTTPError as e :
671+ if e .response is not None :
672+ # Authentication/authorization errors should raise OperationalError
673+ if e .response .status_code in (401 , 403 ):
674+ try :
675+ detail = e .response .json ().get ("detail" , str (e ))
676+ except (ValueError , json .JSONDecodeError ):
677+ detail = e .response .text or str (e )
678+ raise OperationalError (f"Authentication error: { detail } " ) from e
679+ # For other HTTP errors, fall back to status endpoint
650680 except requests .exceptions .RequestException :
651681 pass
652682
0 commit comments