3232 from aws_advanced_python_wrapper .pep249 import Connection
3333 from aws_advanced_python_wrapper .plugin_service import PluginService
3434
35- from aws_advanced_python_wrapper .errors import AwsWrapperError
35+ from aws_advanced_python_wrapper .errors import AwsConnectError , AwsWrapperError
3636from aws_advanced_python_wrapper .pep249_methods import DbApiMethod
3737from aws_advanced_python_wrapper .plugin import Plugin , PluginFactory
3838from aws_advanced_python_wrapper .utils .log import Logger
@@ -113,9 +113,12 @@ def _connect(self, host_info: HostInfo, props: Properties, connect_func: Callabl
113113 return connect_func ()
114114
115115 except Exception as e :
116+ if self ._plugin_service .is_network_exception (error = e ):
117+ raise AwsConnectError (Messages .get_formatted ("AwsSecretsManagerPlugin.ConnectException" , e )) from e
118+
116119 if not self ._plugin_service .is_login_exception (error = e ) or secret_fetched :
117120 raise AwsWrapperError (
118- Messages .get_formatted ("AwsSecretsManagerPlugin.ConnectException" , e )) from e
121+ Messages .get_formatted ("AwsSecretsManagerPlugin.ConnectException" , e ), e ) from e
119122
120123 secret_fetched = self ._update_secret (host_info , props , token_expiration_ns = token_expiration_ns , force_refetch = True )
121124
@@ -126,8 +129,8 @@ def _connect(self, host_info: HostInfo, props: Properties, connect_func: Callabl
126129 except Exception as unhandled_error :
127130 raise AwsWrapperError (
128131 Messages .get_formatted ("AwsSecretsManagerPlugin.UnhandledException" ,
129- unhandled_error )) from unhandled_error
130- raise AwsWrapperError (Messages .get_formatted ("AwsSecretsManagerPlugin.FailedLogin" , e )) from e
132+ unhandled_error ), unhandled_error ) from unhandled_error
133+ raise AwsWrapperError (Messages .get_formatted ("AwsSecretsManagerPlugin.FailedLogin" , e ), e ) from e
131134
132135 def _update_secret (self , host_info : HostInfo , props : Properties , token_expiration_ns : int , force_refetch : bool = False ) -> bool :
133136 """
@@ -154,19 +157,19 @@ def _update_secret(self, host_info: HostInfo, props: Properties, token_expiratio
154157 except (ClientError , AttributeError ) as e :
155158 logger .debug ("AwsSecretsManagerPlugin.FailedToFetchDbCredentials" , e )
156159 raise AwsWrapperError (
157- Messages .get_formatted ("AwsSecretsManagerPlugin.FailedToFetchDbCredentials" , e )) from e
160+ Messages .get_formatted ("AwsSecretsManagerPlugin.FailedToFetchDbCredentials" , e ), e ) from e
158161 except JSONDecodeError as e :
159162 logger .debug ("AwsSecretsManagerPlugin.JsonDecodeError" , e )
160163 raise AwsWrapperError (
161- Messages .get_formatted ("AwsSecretsManagerPlugin.JsonDecodeError" , e ))
162- except EndpointConnectionError :
164+ Messages .get_formatted ("AwsSecretsManagerPlugin.JsonDecodeError" , e ), e ) from e
165+ except EndpointConnectionError as e :
163166 logger .debug ("AwsSecretsManagerPlugin.EndpointOverrideInvalidConnection" , endpoint )
164167 raise AwsWrapperError (
165- Messages .get_formatted ("AwsSecretsManagerPlugin.EndpointOverrideInvalidConnection" , endpoint ))
166- except ValueError :
168+ Messages .get_formatted ("AwsSecretsManagerPlugin.EndpointOverrideInvalidConnection" , endpoint ), e ) from e
169+ except ValueError as e :
167170 logger .debug ("AwsSecretsManagerPlugin.EndpointOverrideMisconfigured" , endpoint )
168171 raise AwsWrapperError (
169- Messages .get_formatted ("AwsSecretsManagerPlugin.EndpointOverrideMisconfigured" , endpoint ))
172+ Messages .get_formatted ("AwsSecretsManagerPlugin.EndpointOverrideMisconfigured" , endpoint ), e ) from e
170173
171174 return fetched
172175 except Exception as ex :
0 commit comments