Skip to content

Commit

Permalink
CDK improve error handling responses (#11629)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marcosmarxm committed Mar 31, 2022
1 parent 57a6353 commit 78cafc5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions airbyte-cdk/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def _send(self, request: requests.PreparedRequest, request_kwargs: Mapping[str,
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
Expand Down
2 changes: 1 addition & 1 deletion airbyte-cdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def max_retries(self):
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
Expand Down Expand Up @@ -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))


Expand Down

0 comments on commit 78cafc5

Please sign in to comment.