Skip to content

Commit

Permalink
improved error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jlloyd-widen committed Aug 27, 2024
1 parent c07fe6b commit 8bc1621
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "acquia-tap-clari"
version = "0.0.2"
version = "0.0.3"
description = "`tap-clari` is a Singer tap for Clari, built with the Meltano Singer SDK."
readme = "README.md"
authors = ["Josh Lloyd <[email protected]>"]
Expand Down
19 changes: 19 additions & 0 deletions tap_clari/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from __future__ import annotations

from http import HTTPStatus
from typing import Any, Callable

import requests
from singer_sdk.authenticators import APIKeyAuthenticator
from singer_sdk.exceptions import RetriableAPIError, FatalAPIError
from singer_sdk.streams import RESTStream

_Auth = Callable[[requests.PreparedRequest], requests.PreparedRequest]
Expand Down Expand Up @@ -73,3 +75,20 @@ def get_url_params(
# "currency": "USD",
"exportFormat": "JSON",
}

def validate_response(self, response: requests.Response) -> None:
"""Validate http response."""
if (
response.status_code in self.extra_retry_statuses
or response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR
):
msg = self.response_error_message(response)
raise RetriableAPIError(msg, response)

if (
HTTPStatus.BAD_REQUEST
<= response.status_code
< HTTPStatus.INTERNAL_SERVER_ERROR
):
msg = self.response_error_message(response) + f". URL: {response.url}"
raise FatalAPIError(msg)

0 comments on commit 8bc1621

Please sign in to comment.