Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Source Hubspot: improve error message during connector setup #28558

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.0
LABEL io.airbyte.version=1.1.1
LABEL io.airbyte.name=airbyte/source-hubspot

Large diffs are not rendered by default.

Expand Up @@ -5,7 +5,7 @@ data:
connectorSubtype: api
connectorType: source
definitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c
dockerImageTag: 1.1.0
dockerImageTag: 1.1.1
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.)"
arsenlosenko marked this conversation as resolved.
Show resolved Hide resolved
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.1 | 2023-07-21 | [28558](https://github.com/airbytehq/airbyte/pull/28558) | Improve error messages during connector setup |
| 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 |
| 1.0.0 | 2023-06-08 | [27161](https://github.com/airbytehq/airbyte/pull/27161) | Fixed increment sync for engagements stream, 'Recent' API is used for recent syncs of last recent 30 days and less than 10k records, otherwise full sync if performed by 'All' API |
Expand Down