Skip to content

Commit

Permalink
reduce _send complexity by pulling our error resolution handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pnilan committed Oct 21, 2024
1 parent 07e618e commit cd3e214
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions airbyte-cdk/python/airbyte_cdk/sources/streams/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import logging
import os
import orjson
import urllib
from pathlib import Path
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union

import orjson
import requests
import requests_cache
from airbyte_cdk.models import (
Expand Down Expand Up @@ -249,7 +249,7 @@ def _send(
self._request_attempt_count[request] = 1
else:
self._request_attempt_count[request] += 1
if isinstance(self._session.auth, AuthBase):
if hasattr(self._session, "auth") and isinstance(self._session.auth, AuthBase):
self._session.auth(request)

self._logger.debug(
Expand Down Expand Up @@ -287,6 +287,20 @@ def _send(
lambda: formatter(response), # type: ignore # log_formatter is always cast to a callable
)

self._handle_error_resolution(
response=response, exc=exc, request=request, error_resolution=error_resolution, exit_on_rate_limit=exit_on_rate_limit
)

return response # type: ignore # will either return a valid response of type requests.Response or raise an exception

def _handle_error_resolution(
self,
response: Optional[requests.Response],
exc: Optional[requests.RequestException],
request: requests.PreparedRequest,
error_resolution: ErrorResolution,
exit_on_rate_limit: Optional[bool] = False,
) -> None:
# Emit stream status RUNNING with the reason RATE_LIMITED to log that the rate limit has been reached
if error_resolution.response_action == ResponseAction.RATE_LIMITED:
# TODO: Update to handle with message repository when concurrent message repository is ready
Expand Down Expand Up @@ -364,8 +378,6 @@ def _send(
self._logger.error(response.text)
raise e

return response # type: ignore # will either return a valid response of type requests.Response or raise an exception

@property
def name(self) -> str:
return self._name
Expand Down

0 comments on commit cd3e214

Please sign in to comment.