diff --git a/airbyte-integrations/connectors/source-freshdesk/source_freshdesk/source.py b/airbyte-integrations/connectors/source-freshdesk/source_freshdesk/source.py index e2ebc32f5e9c..ae73a93d93f1 100644 --- a/airbyte-integrations/connectors/source-freshdesk/source_freshdesk/source.py +++ b/airbyte-integrations/connectors/source-freshdesk/source_freshdesk/source.py @@ -5,6 +5,7 @@ import logging from typing import Any, List, Mapping, Optional, Tuple +import requests from airbyte_cdk.sources import AbstractSource from airbyte_cdk.sources.streams import Stream from requests.auth import HTTPBasicAuth @@ -55,8 +56,16 @@ def _get_stream_kwargs(config: Mapping[str, Any]) -> dict: return {"authenticator": FreshdeskAuth(config["api_key"]), "config": config} def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]: - stream = Settings(**self._get_stream_kwargs(config=config)) - return stream.availability_strategy.check_availability(stream, logger, self) + try: + stream = Settings(**self._get_stream_kwargs(config=config)) + return stream.availability_strategy.check_availability(stream, logger, self) + except requests.HTTPError as error: + body = error.response.json() + error_msg = f"{body.get('code')}: {body.get('message')}" + except Exception as error: + error_msg = repr(error) + + return False, error_msg def streams(self, config: Mapping[str, Any]) -> List[Stream]: return [ diff --git a/airbyte-integrations/connectors/source-freshdesk/unit_tests/test_source.py b/airbyte-integrations/connectors/source-freshdesk/unit_tests/test_source.py index 3aba345f653e..f07f2ad09a2b 100644 --- a/airbyte-integrations/connectors/source-freshdesk/unit_tests/test_source.py +++ b/airbyte-integrations/connectors/source-freshdesk/unit_tests/test_source.py @@ -45,7 +45,7 @@ def test_check_connection_invalid_config(config): assert not ok and error_msg -def test_check_connection_exception(config): +def test_check_connection_exception(requests_mock, config): ok, error_msg = SourceFreshdesk().check_connection(logger, config=config) assert not ok and error_msg