3535 PropertiesUpdateSummary ,
3636)
3737from pyiceberg .catalog .rest .auth import AuthManager , AuthManagerAdapter , AuthManagerFactory , LegacyOAuth2AuthManager
38- from pyiceberg .catalog .rest .response import _handle_non_200_response
38+ from pyiceberg .catalog .rest .response import ErrorHandlers
3939from pyiceberg .exceptions import (
4040 AuthorizationExpiredError ,
41- CommitFailedException ,
42- CommitStateUnknownException ,
43- NamespaceAlreadyExistsError ,
44- NamespaceNotEmptyError ,
4541 NoSuchIdentifierError ,
4642 NoSuchNamespaceError ,
47- NoSuchTableError ,
48- NoSuchViewError ,
49- TableAlreadyExistsError ,
5043 UnauthorizedError ,
5144)
5245from pyiceberg .io import AWS_ACCESS_KEY_ID , AWS_REGION , AWS_SECRET_ACCESS_KEY , AWS_SESSION_TOKEN
6457from pyiceberg .table .metadata import TableMetadata
6558from pyiceberg .table .sorting import UNSORTED_SORT_ORDER , SortOrder , assign_fresh_sort_order_ids
6659from pyiceberg .table .update import (
60+ AssertCreate ,
6761 TableRequirement ,
6862 TableUpdate ,
6963)
@@ -361,7 +355,7 @@ def _fetch_config(self) -> None:
361355 try :
362356 response .raise_for_status ()
363357 except HTTPError as exc :
364- _handle_non_200_response (exc , {} )
358+ ErrorHandlers . default_error_handler (exc )
365359 config_response = ConfigResponse .model_validate_json (response .text )
366360
367361 config = config_response .defaults
@@ -519,7 +513,7 @@ def _create_table(
519513 try :
520514 response .raise_for_status ()
521515 except HTTPError as exc :
522- _handle_non_200_response (exc , { 409 : TableAlreadyExistsError , 404 : NoSuchNamespaceError } )
516+ ErrorHandlers . table_error_handler (exc )
523517 return TableResponse .model_validate_json (response .text )
524518
525519 @retry (** _RETRY_ARGS )
@@ -592,7 +586,7 @@ def register_table(self, identifier: str | Identifier, metadata_location: str) -
592586 try :
593587 response .raise_for_status ()
594588 except HTTPError as exc :
595- _handle_non_200_response (exc , { 409 : TableAlreadyExistsError } )
589+ ErrorHandlers . table_error_handler (exc )
596590
597591 table_response = TableResponse .model_validate_json (response .text )
598592 return self ._response_to_table (self .identifier_to_tuple (identifier ), table_response )
@@ -605,7 +599,7 @@ def list_tables(self, namespace: str | Identifier) -> list[Identifier]:
605599 try :
606600 response .raise_for_status ()
607601 except HTTPError as exc :
608- _handle_non_200_response (exc , { 404 : NoSuchNamespaceError } )
602+ ErrorHandlers . namespace_error_handler (exc )
609603 return [(* table .namespace , table .name ) for table in ListTablesResponse .model_validate_json (response .text ).identifiers ]
610604
611605 @retry (** _RETRY_ARGS )
@@ -623,7 +617,7 @@ def load_table(self, identifier: str | Identifier) -> Table:
623617 try :
624618 response .raise_for_status ()
625619 except HTTPError as exc :
626- _handle_non_200_response (exc , { 404 : NoSuchTableError } )
620+ ErrorHandlers . table_error_handler (exc )
627621
628622 table_response = TableResponse .model_validate_json (response .text )
629623 return self ._response_to_table (self .identifier_to_tuple (identifier ), table_response )
@@ -637,7 +631,7 @@ def drop_table(self, identifier: str | Identifier, purge_requested: bool = False
637631 try :
638632 response .raise_for_status ()
639633 except HTTPError as exc :
640- _handle_non_200_response (exc , { 404 : NoSuchTableError } )
634+ ErrorHandlers . table_error_handler (exc )
641635
642636 @retry (** _RETRY_ARGS )
643637 def purge_table (self , identifier : str | Identifier ) -> None :
@@ -663,7 +657,7 @@ def rename_table(self, from_identifier: str | Identifier, to_identifier: str | I
663657 try :
664658 response .raise_for_status ()
665659 except HTTPError as exc :
666- _handle_non_200_response (exc , { 404 : NoSuchTableError , 409 : TableAlreadyExistsError } )
660+ ErrorHandlers . table_error_handler (exc )
667661
668662 return self .load_table (to_identifier )
669663
@@ -686,7 +680,7 @@ def list_views(self, namespace: str | Identifier) -> list[Identifier]:
686680 try :
687681 response .raise_for_status ()
688682 except HTTPError as exc :
689- _handle_non_200_response (exc , { 404 : NoSuchNamespaceError } )
683+ ErrorHandlers . view_error_handler (exc )
690684 return [(* view .namespace , view .name ) for view in ListViewsResponse .model_validate_json (response .text ).identifiers ]
691685
692686 @retry (** _RETRY_ARGS )
@@ -724,15 +718,10 @@ def commit_table(
724718 try :
725719 response .raise_for_status ()
726720 except HTTPError as exc :
727- _handle_non_200_response (
728- exc ,
729- {
730- 409 : CommitFailedException ,
731- 500 : CommitStateUnknownException ,
732- 502 : CommitStateUnknownException ,
733- 504 : CommitStateUnknownException ,
734- },
735- )
721+ if AssertCreate () in requirements :
722+ ErrorHandlers .table_error_handler (exc )
723+ else :
724+ ErrorHandlers .commit_error_handler (exc )
736725 return CommitTableResponse .model_validate_json (response .text )
737726
738727 @retry (** _RETRY_ARGS )
@@ -743,7 +732,7 @@ def create_namespace(self, namespace: str | Identifier, properties: Properties =
743732 try :
744733 response .raise_for_status ()
745734 except HTTPError as exc :
746- _handle_non_200_response (exc , { 409 : NamespaceAlreadyExistsError } )
735+ ErrorHandlers . namespace_error_handler (exc )
747736
748737 @retry (** _RETRY_ARGS )
749738 def drop_namespace (self , namespace : str | Identifier ) -> None :
@@ -753,7 +742,7 @@ def drop_namespace(self, namespace: str | Identifier) -> None:
753742 try :
754743 response .raise_for_status ()
755744 except HTTPError as exc :
756- _handle_non_200_response (exc , { 404 : NoSuchNamespaceError , 409 : NamespaceNotEmptyError } )
745+ ErrorHandlers . drop_namespace_error_handler (exc )
757746
758747 @retry (** _RETRY_ARGS )
759748 def list_namespaces (self , namespace : str | Identifier = ()) -> list [Identifier ]:
@@ -768,7 +757,7 @@ def list_namespaces(self, namespace: str | Identifier = ()) -> list[Identifier]:
768757 try :
769758 response .raise_for_status ()
770759 except HTTPError as exc :
771- _handle_non_200_response (exc , { 404 : NoSuchNamespaceError } )
760+ ErrorHandlers . namespace_error_handler (exc )
772761
773762 return ListNamespaceResponse .model_validate_json (response .text ).namespaces
774763
@@ -780,7 +769,7 @@ def load_namespace_properties(self, namespace: str | Identifier) -> Properties:
780769 try :
781770 response .raise_for_status ()
782771 except HTTPError as exc :
783- _handle_non_200_response (exc , { 404 : NoSuchNamespaceError } )
772+ ErrorHandlers . namespace_error_handler (exc )
784773
785774 return NamespaceResponse .model_validate_json (response .text ).properties
786775
@@ -795,7 +784,7 @@ def update_namespace_properties(
795784 try :
796785 response .raise_for_status ()
797786 except HTTPError as exc :
798- _handle_non_200_response (exc , { 404 : NoSuchNamespaceError } )
787+ ErrorHandlers . namespace_error_handler (exc )
799788 parsed_response = UpdateNamespacePropertiesResponse .model_validate_json (response .text )
800789 return PropertiesUpdateSummary (
801790 removed = parsed_response .removed ,
@@ -817,7 +806,7 @@ def namespace_exists(self, namespace: str | Identifier) -> bool:
817806 try :
818807 response .raise_for_status ()
819808 except HTTPError as exc :
820- _handle_non_200_response (exc , {} )
809+ ErrorHandlers . namespace_error_handler (exc )
821810
822811 return False
823812
@@ -843,7 +832,7 @@ def table_exists(self, identifier: str | Identifier) -> bool:
843832 try :
844833 response .raise_for_status ()
845834 except HTTPError as exc :
846- _handle_non_200_response (exc , {} )
835+ ErrorHandlers . table_error_handler (exc )
847836
848837 return False
849838
@@ -868,7 +857,7 @@ def view_exists(self, identifier: str | Identifier) -> bool:
868857 try :
869858 response .raise_for_status ()
870859 except HTTPError as exc :
871- _handle_non_200_response (exc , {} )
860+ ErrorHandlers . view_error_handler (exc )
872861
873862 return False
874863
@@ -880,7 +869,7 @@ def drop_view(self, identifier: str) -> None:
880869 try :
881870 response .raise_for_status ()
882871 except HTTPError as exc :
883- _handle_non_200_response (exc , { 404 : NoSuchViewError } )
872+ ErrorHandlers . view_error_handler (exc )
884873
885874 def close (self ) -> None :
886875 """Close the catalog and release Session connection adapters.
0 commit comments