Skip to content

Commit

Permalink
✨ Source Hubspot: improve error message during connector setup (#28558)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
arsenlosenko committed Jul 27, 2023
1 parent 9cee15b commit 277711a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-hubspot/Dockerfile
Expand Up @@ -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
Expand Up @@ -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
Expand Down
Expand Up @@ -3,6 +3,7 @@
#

import logging
from http import HTTPStatus
from itertools import chain
from typing import Any, List, Mapping, Optional, Tuple

Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
Expand Up @@ -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"}}
Expand Down
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/hubspot.md
Expand Up @@ -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 |
Expand Down

0 comments on commit 277711a

Please sign in to comment.