|
5 | 5 | import logging
|
6 | 6 | from typing import Any, List, Mapping, Optional, Tuple
|
7 | 7 |
|
| 8 | +import requests |
8 | 9 | from airbyte_cdk.sources import AbstractSource
|
9 | 10 | from airbyte_cdk.sources.streams import Stream
|
10 | 11 | from requests.auth import HTTPBasicAuth
|
@@ -55,8 +56,16 @@ def _get_stream_kwargs(config: Mapping[str, Any]) -> dict:
|
55 | 56 | return {"authenticator": FreshdeskAuth(config["api_key"]), "config": config}
|
56 | 57 |
|
57 | 58 | def check_connection(self, logger: logging.Logger, config: Mapping[str, Any]) -> Tuple[bool, Optional[Any]]:
|
58 |
| - stream = Settings(**self._get_stream_kwargs(config=config)) |
59 |
| - return stream.availability_strategy.check_availability(stream, logger, self) |
| 59 | + try: |
| 60 | + stream = Settings(**self._get_stream_kwargs(config=config)) |
| 61 | + return stream.availability_strategy.check_availability(stream, logger, self) |
| 62 | + except requests.HTTPError as error: |
| 63 | + body = error.response.json() |
| 64 | + error_msg = f"{body.get('code')}: {body.get('message')}" |
| 65 | + except Exception as error: |
| 66 | + error_msg = repr(error) |
| 67 | + |
| 68 | + return False, error_msg |
60 | 69 |
|
61 | 70 | def streams(self, config: Mapping[str, Any]) -> List[Stream]:
|
62 | 71 | return [
|
|
0 commit comments