1
0
mirror of synced 2025-12-25 02:09:19 -05:00

CDK improve error handling responses (#11629)

* add response text and message to backoff error handling

* add response text and message to backoff error handling

* add response text case http error

* change response text to before raise error

* apply suggestions

* bump cdk version
This commit is contained in:
Marcos Marx
2022-03-31 16:41:10 -03:00
committed by GitHub
parent 57a6353668
commit 78cafc58ab
5 changed files with 9 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
# Changelog
## 0.1.50
Improve logging for Error handling during send process.
## 0.1.49
Add support for streams with explicit state attribute.

View File

@@ -9,7 +9,9 @@ import requests
class BaseBackoffException(requests.exceptions.HTTPError):
pass
def __init__(self, request: requests.PreparedRequest, response: requests.Response):
error_message = f"Request URL: {request.url}, Response Code: {response.status_code}, Response Text: {response.text}"
super().__init__(error_message)
class RequestBodyException(Exception):

View File

@@ -294,6 +294,7 @@ class HttpStream(Stream, ABC):
raise DefaultBackoffException(request=request, response=response)
elif self.raise_on_http_errors:
# Raise any HTTP exceptions that happened in case there were unexpected ones
self.logger.error(f"Request raised an error with response: {response.text}")
response.raise_for_status()
return response

View File

@@ -15,7 +15,7 @@ README = (HERE / "README.md").read_text()
setup(
name="airbyte-cdk",
version="0.1.49",
version="0.1.50",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",

View File

@@ -167,7 +167,7 @@ def test_stub_custom_backoff_http_stream_retries(mocker, retries):
req.status_code = HTTPStatus.TOO_MANY_REQUESTS
send_mock = mocker.patch.object(requests.Session, "send", return_value=req)
with pytest.raises(UserDefinedBackoffException):
with pytest.raises(UserDefinedBackoffException, match="Request URL: https://test_base_url.com/, Response Code: 429"):
list(stream.read_records(SyncMode.full_refresh))
if retries <= 0:
assert send_mock.call_count == 1
@@ -219,7 +219,7 @@ def test_raise_on_http_errors_off_429(mocker):
req.status_code = 429
mocker.patch.object(requests.Session, "send", return_value=req)
with pytest.raises(DefaultBackoffException):
with pytest.raises(DefaultBackoffException, match="Request URL: https://test_base_url.com/, Response Code: 429"):
list(stream.read_records(SyncMode.full_refresh))