From 277711acaef2ee3fd2df98ed7acc8824009acac0 Mon Sep 17 00:00:00 2001 From: Arsen Losenko <20901439+arsenlosenko@users.noreply.github.com> Date: Thu, 27 Jul 2023 14:20:35 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Source=20Hubspot:=20improve=20error?= =?UTF-8?q?=20message=20during=20connector=20setup=20(#28558)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Source Hubspot: improve error message during connector setup * Update changelog * Fix import order * Fix linting errors * Update contacts expected records * update error message * Update version --- .../connectors/source-hubspot/Dockerfile | 2 +- .../connectors/source-hubspot/metadata.yaml | 2 +- .../connectors/source-hubspot/source_hubspot/source.py | 8 ++++++++ .../connectors/source-hubspot/unit_tests/conftest.py | 5 +++++ .../source-hubspot/unit_tests/test_source.py | 10 ++++++++++ docs/integrations/sources/hubspot.md | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/airbyte-integrations/connectors/source-hubspot/Dockerfile b/airbyte-integrations/connectors/source-hubspot/Dockerfile index f0e628b5da008..d9aa78c6452e3 100644 --- a/airbyte-integrations/connectors/source-hubspot/Dockerfile +++ b/airbyte-integrations/connectors/source-hubspot/Dockerfile @@ -34,5 +34,5 @@ COPY source_hubspot ./source_hubspot ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py" ENTRYPOINT ["python", "/airbyte/integration_code/main.py"] -LABEL io.airbyte.version=1.1.1 +LABEL io.airbyte.version=1.1.2 LABEL io.airbyte.name=airbyte/source-hubspot diff --git a/airbyte-integrations/connectors/source-hubspot/metadata.yaml b/airbyte-integrations/connectors/source-hubspot/metadata.yaml index 5b06a7de4a2a2..6bbe5987df760 100644 --- a/airbyte-integrations/connectors/source-hubspot/metadata.yaml +++ b/airbyte-integrations/connectors/source-hubspot/metadata.yaml @@ -5,7 +5,7 @@ data: connectorSubtype: api connectorType: source definitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c - dockerImageTag: 1.1.1 + dockerImageTag: 1.1.2 dockerRepository: airbyte/source-hubspot githubIssueLabel: source-hubspot icon: hubspot.svg diff --git a/airbyte-integrations/connectors/source-hubspot/source_hubspot/source.py b/airbyte-integrations/connectors/source-hubspot/source_hubspot/source.py index 65dd38811affa..e9b6f3b633c9c 100644 --- a/airbyte-integrations/connectors/source-hubspot/source_hubspot/source.py +++ b/airbyte-integrations/connectors/source-hubspot/source_hubspot/source.py @@ -3,6 +3,7 @@ # import logging +from http import HTTPStatus from itertools import chain from typing import Any, List, Mapping, Optional, Tuple @@ -11,6 +12,7 @@ from airbyte_cdk.sources import AbstractSource from airbyte_cdk.sources.streams import Stream from requests import HTTPError +from source_hubspot.errors import HubspotInvalidAuth from source_hubspot.streams import ( API, Campaigns, @@ -56,9 +58,15 @@ def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> try: contacts = Contacts(**common_params) _ = contacts.properties + except HubspotInvalidAuth: + alive = False + error_msg = "Authentication failed: Please check if provided credentials are valid and try again." except HTTPError as error: alive = False error_msg = repr(error) + if error.response.status_code == HTTPStatus.BAD_REQUEST: + response_json = error.response.json() + error_msg = f"400 Bad Request: {response_json['message']}, please check if provided credentials are valid." return alive, error_msg def get_granted_scopes(self, authenticator): diff --git a/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py b/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py index a4cde6bb62eb7..0c4ff9c8f613c 100644 --- a/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py +++ b/airbyte-integrations/connectors/source-hubspot/unit_tests/conftest.py @@ -32,6 +32,11 @@ def common_params_fixture(config): return common_params +@pytest.fixture(name="config_invalid_client_id") +def config_invalid_client_id_fixture(): + return {"start_date": "2021-01-10T00:00:00Z", "credentials": {"credentials_title": "OAuth Credentials", "client_id": "invalid_client_id", "client_secret": "invalid_client_secret", "access_token": "test_access_token", "refresh_token": "test_refresh_token"}} + + @pytest.fixture(name="config") def config_fixture(): return {"start_date": "2021-01-10T00:00:00Z", "credentials": {"credentials_title": "Private App Credentials", "access_token": "test_access_token"}} diff --git a/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py b/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py index 03ee3c5ec339d..0af68fcf3441a 100644 --- a/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py +++ b/airbyte-integrations/connectors/source-hubspot/unit_tests/test_source.py @@ -63,6 +63,16 @@ def test_check_connection_exception(config): assert error_msg +def test_check_connection_bad_request_exception(requests_mock, config_invalid_client_id): + responses = [ + {"json": {"message": "invalid client_id"}, "status_code": 400}, + ] + requests_mock.register_uri("POST", "/oauth/v1/token", responses) + ok, error_msg = SourceHubspot().check_connection(logger, config=config_invalid_client_id) + assert not ok + assert error_msg + + def test_check_connection_invalid_start_date_exception(config_invalid_date): with pytest.raises(InvalidStartDateConfigError): ok, error_msg = SourceHubspot().check_connection(logger, config=config_invalid_date) diff --git a/docs/integrations/sources/hubspot.md b/docs/integrations/sources/hubspot.md index 6fac69289bc83..51e28baf39bee 100644 --- a/docs/integrations/sources/hubspot.md +++ b/docs/integrations/sources/hubspot.md @@ -197,6 +197,7 @@ Now that you have set up the Hubspot source connector, check out the following H | Version | Date | Pull Request | Subject | |:--------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 1.1.2 | 2023-07-27 | [28558](https://github.com/airbytehq/airbyte/pull/28558) | Improve error messages during connector setup | | 1.1.1 | 2023-07-25 | [28705](https://github.com/airbytehq/airbyte/pull/28705) | Fix retry handler for token expired error | | 1.1.0 | 2023-07-18 | [28349](https://github.com/airbytehq/airbyte/pull/28349) | Add unexpected fields in schemas of streams `email_events`, `email_subscriptions`, `engagements`, `campaigns` | | 1.0.1 | 2023-06-23 | [27658](https://github.com/airbytehq/airbyte/pull/27658) | Use fully qualified name to retrieve custom objects |