diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index 3d5e16758d5..638d13d9380 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -58,7 +58,7 @@ def handle_exception(ex): # pylint: disable=too-many-locals, too-many-statement from msrestazure.azure_exceptions import CloudError from msrest.exceptions import HttpOperationError, ValidationError, ClientRequestError from azure.common import AzureException - from azure.core.exceptions import AzureError + from azure.core.exceptions import AzureError, ServiceRequestError from requests.exceptions import SSLError, HTTPError from azure.cli.core import azclierror from msal_extensions.persistence import PersistenceError @@ -79,7 +79,11 @@ def handle_exception(ex): # pylint: disable=too-many-locals, too-many-statement az_error = azclierror.InvalidArgumentValueError(error_msg) az_error.set_recommendation(QUERY_REFERENCE) - elif isinstance(ex, SSLError): + # SSLError is raised when making HTTP requests with 'requests' lib behind a proxy that intercepts HTTPS traffic. + # - SSLError is raised when directly calling 'requests' lib, such as MSAL or `az rest` + # - azure.core.exceptions.ServiceRequestError is raised when indirectly calling 'requests' lib with azure.core, + # which wraps the original SSLError + elif isinstance(ex, SSLError) or isinstance(ex, ServiceRequestError) and isinstance(ex.inner_exception, SSLError): az_error = azclierror.AzureConnectionError(error_msg) az_error.set_recommendation(SSLERROR_TEMPLATE)