From 8bc1621e3cfd503132c9c31d4b1b253d4c9916a0 Mon Sep 17 00:00:00 2001 From: Josh lloyd Date: Tue, 27 Aug 2024 09:48:49 -0600 Subject: [PATCH] improved error responses --- pyproject.toml | 2 +- tap_clari/client.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b138737..c81062f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] diff --git a/tap_clari/client.py b/tap_clari/client.py index 1e61408..edd5e37 100644 --- a/tap_clari/client.py +++ b/tap_clari/client.py @@ -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] @@ -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)