Skip to content

Commit b6dd0fa

Browse files
author
maxime.c
committed
poc
1 parent 035264c commit b6dd0fa

File tree

9 files changed

+14
-88
lines changed

9 files changed

+14
-88
lines changed

airbyte_cdk/sources/declarative/parsers/model_to_component_factory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,9 +2277,6 @@ def create_default_error_handler(
22772277
response_filters.append(
22782278
self._create_component_from_model(model=response_filter_model, config=config)
22792279
)
2280-
response_filters.append(
2281-
HttpResponseFilter(config=config, parameters=model.parameters or {})
2282-
)
22832280

22842281
return DefaultErrorHandler(
22852282
backoff_strategies=backoff_strategies,

airbyte_cdk/sources/declarative/requesters/error_handlers/composite_error_handler.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,13 @@ def max_time(self) -> Optional[int]:
5858

5959
def interpret_response(
6060
self, response_or_exception: Optional[Union[requests.Response, Exception]]
61-
) -> ErrorResolution:
62-
matched_error_resolution = None
61+
) -> Optional[ErrorResolution]:
6362
for error_handler in self.error_handlers:
6463
matched_error_resolution = error_handler.interpret_response(response_or_exception)
6564

66-
if not isinstance(matched_error_resolution, ErrorResolution):
67-
continue
68-
69-
if matched_error_resolution.response_action in [
70-
ResponseAction.SUCCESS,
71-
ResponseAction.RETRY,
72-
ResponseAction.IGNORE,
73-
ResponseAction.RESET_PAGINATION,
74-
]:
65+
if isinstance(matched_error_resolution, ErrorResolution):
7566
return matched_error_resolution
7667

77-
if matched_error_resolution:
78-
return matched_error_resolution
79-
8068
return create_fallback_error_resolution(response_or_exception)
8169

8270
@property

airbyte_cdk/sources/declarative/requesters/error_handlers/default_error_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def interpret_response(
122122
if response_or_exception.ok:
123123
return SUCCESS_RESOLUTION
124124

125-
default_reponse_filter = DefaultHttpResponseFilter(parameters={}, config=self.config)
126-
default_response_filter_resolution = default_reponse_filter.matches(response_or_exception)
125+
default_response_filter = DefaultHttpResponseFilter(parameters={}, config=self.config)
126+
default_response_filter_resolution = default_response_filter.matches(response_or_exception)
127127

128128
return (
129129
default_response_filter_resolution

airbyte_cdk/sources/streams/http/error_handlers/error_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def max_time(self) -> Optional[int]:
3232
@abstractmethod
3333
def interpret_response(
3434
self, response: Optional[Union[requests.Response, Exception]]
35-
) -> ErrorResolution:
35+
) -> Optional[ErrorResolution]:
3636
"""
3737
Interpret the response or exception and return the corresponding response action, failure type, and error message.
3838

airbyte_cdk/sources/streams/http/error_handlers/http_status_error_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def max_time(self) -> Optional[int]:
4747

4848
def interpret_response(
4949
self, response_or_exception: Optional[Union[requests.Response, Exception]] = None
50-
) -> ErrorResolution:
50+
) -> Optional[ErrorResolution]:
5151
"""
5252
Interpret the response and return the corresponding response action, failure type, and error message.
5353

airbyte_cdk/sources/streams/http/error_handlers/response_models.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,8 @@ def _format_response_error_message(response: requests.Response) -> str:
4545

4646
def create_fallback_error_resolution(
4747
response_or_exception: Optional[Union[requests.Response, Exception]],
48-
) -> ErrorResolution:
49-
if response_or_exception is None:
50-
# We do not expect this case to happen but if it does, it would be good to understand the cause and improve the error message
51-
error_message = "Error handler did not receive a valid response or exception. This is unexpected please contact Airbyte Support"
52-
elif isinstance(response_or_exception, Exception):
53-
error_message = _format_exception_error_message(response_or_exception)
54-
else:
55-
error_message = _format_response_error_message(response_or_exception)
56-
57-
return ErrorResolution(
58-
response_action=ResponseAction.RETRY,
59-
failure_type=FailureType.system_error,
60-
error_message=error_message,
61-
)
48+
) -> None:
49+
return None
6250

6351

6452
SUCCESS_RESOLUTION = ErrorResolution(

airbyte_cdk/sources/streams/http/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def __init__(self, stream: HttpStream, **kwargs): # type: ignore # noqa
628628

629629
def interpret_response(
630630
self, response_or_exception: Optional[Union[requests.Response, Exception]] = None
631-
) -> ErrorResolution:
631+
) -> Optional[ErrorResolution]:
632632
if isinstance(response_or_exception, Exception):
633633
return super().interpret_response(response_or_exception)
634634
elif isinstance(response_or_exception, requests.Response):

airbyte_cdk/sources/streams/http/http_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def _send(
342342
except requests.RequestException as e:
343343
exc = e
344344

345-
error_resolution: ErrorResolution = self._error_handler.interpret_response(
345+
error_resolution: Optional[ErrorResolution] = self._error_handler.interpret_response(
346346
response if response is not None else exc
347347
)
348348

@@ -380,7 +380,7 @@ def _send(
380380
response=response,
381381
exc=exc,
382382
request=request,
383-
error_resolution=error_resolution,
383+
error_resolution=error_resolution if error_resolution else ErrorResolution(ResponseAction.SUCCESS),
384384
exit_on_rate_limit=exit_on_rate_limit,
385385
)
386386

unit_tests/sources/streams/http/error_handlers/test_response_models.py

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
22

33
from unittest import TestCase
4+
from unittest.mock import Mock
45

56
import requests
67
import requests_mock
@@ -27,56 +28,8 @@ def tearDown(self) -> None:
2728
def test_given_none_when_create_fallback_error_resolution_then_return_error_resolution(
2829
self,
2930
) -> None:
30-
error_resolution = create_fallback_error_resolution(None)
31-
32-
assert error_resolution.failure_type == FailureType.system_error
33-
assert error_resolution.response_action == ResponseAction.RETRY
34-
assert (
35-
error_resolution.error_message
36-
== "Error handler did not receive a valid response or exception. This is unexpected please contact Airbyte Support"
37-
)
38-
39-
def test_given_exception_when_create_fallback_error_resolution_then_return_error_resolution(
40-
self,
41-
) -> None:
42-
exception = ValueError("This is an exception")
43-
44-
error_resolution = create_fallback_error_resolution(exception)
45-
46-
assert error_resolution.failure_type == FailureType.system_error
47-
assert error_resolution.response_action == ResponseAction.RETRY
48-
assert error_resolution.error_message
49-
assert "ValueError" in error_resolution.error_message
50-
assert str(exception) in error_resolution.error_message
51-
52-
def test_given_response_can_raise_for_status_when_create_fallback_error_resolution_then_error_resolution(
53-
self,
54-
) -> None:
55-
response = self._create_response(512)
56-
57-
error_resolution = create_fallback_error_resolution(response)
58-
59-
assert error_resolution.failure_type == FailureType.system_error
60-
assert error_resolution.response_action == ResponseAction.RETRY
61-
assert (
62-
error_resolution.error_message
63-
and "512 Server Error: None for url: https://a-url.com/"
64-
in error_resolution.error_message
65-
)
66-
67-
def test_given_response_is_ok_when_create_fallback_error_resolution_then_error_resolution(
68-
self,
69-
) -> None:
70-
response = self._create_response(205)
71-
72-
error_resolution = create_fallback_error_resolution(response)
73-
74-
assert error_resolution.failure_type == FailureType.system_error
75-
assert error_resolution.response_action == ResponseAction.RETRY
76-
assert (
77-
error_resolution.error_message
78-
and str(response.status_code) in error_resolution.error_message
79-
)
31+
any_response_or_exception = Mock()
32+
assert create_fallback_error_resolution(any_response_or_exception) is None
8033

8134
def _create_response(self, status_code: int) -> requests.Response:
8235
with requests_mock.Mocker() as http_mocker:

0 commit comments

Comments
 (0)