Skip to content

Commit

Permalink
🐛 Source Zendesk Support: Add handle 404 error (#28397)
Browse files Browse the repository at this point in the history
* Add handle 404 error

* Updated PR number

* Updated version
  • Loading branch information
lazebnyi authored Jul 25, 2023
1 parent 5930009 commit 8f92798
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ COPY source_zendesk_support ./source_zendesk_support
ENV AIRBYTE_ENTRYPOINT "python /airbyte/integration_code/main.py"
ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]

LABEL io.airbyte.version=0.10.3
LABEL io.airbyte.version=0.10.4
LABEL io.airbyte.name=airbyte/source-zendesk-support
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data:
connectorType: source
maxSecondsBetweenMessages: 10800
definitionId: 79c1aa37-dae3-42ae-b333-d1c105477715
dockerImageTag: 0.10.3
dockerImageTag: 0.10.4
dockerRepository: airbyte/source-zendesk-support
githubIssueLabel: source-zendesk-support
icon: zendesk-support.svg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ def parse_response(self, response: requests.Response, stream_state: Mapping[str,
yield record

def should_retry(self, response: requests.Response) -> bool:
if response.status_code == 403:
status_code = response.status_code
if status_code == 403 or status_code == 404:
try:
error = response.json().get("error")
except requests.exceptions.JSONDecodeError:
error = {"title": "Forbidden", "message": "Received empty JSON response"}
reason = response.reason
error = {"title": f"{reason}", "message": "Received empty JSON response"}
self.logger.error(f"Skipping stream {self.name}: Check permissions, error message: {error}.")
setattr(self, "raise_on_http_errors", False)
return False
Expand Down Expand Up @@ -227,7 +229,7 @@ def next_page_token(self, response: requests.Response) -> Optional[Mapping[str,
if self._ignore_pagination:
return None

meta = response.json().get("meta", {})
meta = response.json().get("meta", {}) if response.content else {}
return {"page[after]": meta.get("after_cursor")} if meta.get("has_more") else None

def request_params(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,28 @@ def test_check(response, start_date, check_passed):


@pytest.mark.parametrize(
"ticket_forms_response, status_code, expected_n_streams, expected_warnings",
"ticket_forms_response, status_code, expected_n_streams, expected_warnings, reason",
[
({"ticket_forms": [{"id": 1, "updated_at": "2021-07-08T00:05:45Z"}]}, 200, 27, []),
('{"ticket_forms": [{"id": 1, "updated_at": "2021-07-08T00:05:45Z"}]}', 200, 27, [], None),
(
{"error": "Not sufficient permissions"},
'{"error": "Not sufficient permissions"}',
403,
24,
["Skipping stream ticket_forms: Check permissions, error message: Not sufficient permissions."],
None
),
(
'',
404,
24,
["Skipping stream ticket_forms: Check permissions, error message: {'title': 'Not Found', 'message': 'Received empty JSON response'}."],
'Not Found'
),
],
ids=["forms_accessible", "forms_inaccessible"],
ids=["forms_accessible", "forms_inaccessible", "forms_not_exists"],
)
def test_full_access_streams(caplog, requests_mock, ticket_forms_response, status_code, expected_n_streams, expected_warnings):
requests_mock.get("/api/v2/ticket_forms", status_code=status_code, json=ticket_forms_response)
def test_full_access_streams(caplog, requests_mock, ticket_forms_response, status_code, expected_n_streams, expected_warnings, reason):
requests_mock.get("/api/v2/ticket_forms", status_code=status_code, text=ticket_forms_response, reason=reason)
result = SourceZendeskSupport().streams(config=TEST_CONFIG)
assert len(result) == expected_n_streams
logged_warnings = iter([record for record in caplog.records if record.levelname == "ERROR"])
Expand Down
3 changes: 2 additions & 1 deletion docs/integrations/sources/zendesk-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ The Zendesk connector ideally should not run into Zendesk API limitations under

| Version | Date | Pull Request | Subject |
|:---------|:-----------|:---------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `0.10.4` | 2023-07-25 | [28397](https://github.com/airbytehq/airbyte/pull/28397) | Handle 404 Error |
| `0.10.3` | 2023-07-24 | [28612](https://github.com/airbytehq/airbyte/pull/28612) | Fix pagination for stream `TicketMetricEvents` |
| `0.10.2` | 2023-07-19 | [28487](https://github.com/airbytehq/airbyte/pull/28487) | Remove extra page from params |
| `0.10.1` | 2023-07-10 | [28096](https://github.com/airbytehq/airbyte/pull/28096) | Replace `offset` pagination with `cursor` pagination |
| `0.10.0` | 2023-07-06 | [27991](https://github.com/airbytehq/airbyte/pull/27991) | add streams: `PostVotes`, `PostCommentVotes` |
| `0.10.0` | 2023-07-06 | [27991](https://github.com/airbytehq/airbyte/pull/27991) | Add streams: `PostVotes`, `PostCommentVotes` |
| `0.9.0` | 2023-07-05 | [27961](https://github.com/airbytehq/airbyte/pull/27961) | Add stream: `Post Comments` |
| `0.8.1` | 2023-06-27 | [27765](https://github.com/airbytehq/airbyte/pull/27765) | Bugfix: Nonetype error while syncing more then 100000 organizations |
| `0.8.0` | 2023-06-09 | [27156](https://github.com/airbytehq/airbyte/pull/27156) | Add stream `Posts` |
Expand Down

0 comments on commit 8f92798

Please sign in to comment.