-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Source Shopify: add resiliency on some transient errors using the H…
…ttpClient (#38084) Co-authored-by: Oleksandr Bazarnov <oleksandr.bazarnov@globallogic.com> Co-authored-by: maxi297 <maxime@airbyte.io> Co-authored-by: Maxime Carbonneau-Leclerc <3360483+maxi297@users.noreply.github.com>
- Loading branch information
1 parent
df39bf8
commit 64d39cb
Showing
19 changed files
with
976 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
340 changes: 324 additions & 16 deletions
340
airbyte-integrations/connectors/source-shopify/poetry.lock
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
airbyte-integrations/connectors/source-shopify/source_shopify/http_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
|
||
from typing import Optional, Union | ||
|
||
import requests | ||
from airbyte_cdk.sources.streams.http.error_handlers import ErrorHandler, ErrorResolution, ResponseAction | ||
from airbyte_protocol.models import FailureType | ||
from requests import exceptions | ||
|
||
RESPONSE_CONSUMPTION_EXCEPTIONS = ( | ||
exceptions.ChunkedEncodingError, | ||
exceptions.JSONDecodeError, | ||
) | ||
|
||
TRANSIENT_EXCEPTIONS = ( | ||
exceptions.ConnectTimeout, | ||
exceptions.ConnectionError, | ||
exceptions.HTTPError, | ||
exceptions.ReadTimeout, | ||
# This error was added as part of the migration from REST to bulk (https://github.com/airbytehq/airbyte/commit/f5094041bebb80cd6602a98829c19a7515276ed3) but it is unclear in which case it occurs and why it is transient | ||
exceptions.SSLError, | ||
) + RESPONSE_CONSUMPTION_EXCEPTIONS | ||
|
||
_NO_ERROR_RESOLUTION = ErrorResolution(ResponseAction.SUCCESS, None, None) | ||
|
||
|
||
class ShopifyErrorHandler(ErrorHandler): | ||
def __init__(self, stream_name: str = "<no specified stream>") -> None: | ||
self._stream_name = stream_name | ||
|
||
def interpret_response(self, response: Optional[Union[requests.Response, Exception]]) -> ErrorResolution: | ||
if isinstance(response, TRANSIENT_EXCEPTIONS): | ||
return ErrorResolution( | ||
ResponseAction.RETRY, | ||
FailureType.transient_error, | ||
f"Error of type {type(response)} is considered transient. Try again later. (full error message is {response})", | ||
) | ||
elif isinstance(response, requests.Response): | ||
if response.ok: | ||
return _NO_ERROR_RESOLUTION | ||
|
||
if response.status_code == 429 or response.status_code >= 500: | ||
return ErrorResolution( | ||
ResponseAction.RETRY, | ||
FailureType.transient_error, | ||
f"Status code `{response.status_code}` is considered transient. Try again later. (full error message is {response.content})", | ||
) | ||
|
||
return _NO_ERROR_RESOLUTION # Not all the error handling is defined here so it assumes the previous code will handle the error if there is one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.