From c8232d1454218c22b213166e2ba8bd8ee4a69413 Mon Sep 17 00:00:00 2001 From: Derek Visch Date: Fri, 27 Dec 2024 14:59:07 -0500 Subject: [PATCH] Add response information for debugging (#9) --- tap_adp/client.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tap_adp/client.py b/tap_adp/client.py index 056de0e..0d2050e 100644 --- a/tap_adp/client.py +++ b/tap_adp/client.py @@ -113,3 +113,29 @@ def has_more(self, response: requests.Response) -> bool: `True` if pagination should continue, `False` if a 204 No Content is received. """ return response.status_code != 204 + + def response_error_message(self, response: requests.Response) -> str: + """Build error message for invalid http statuses. + + WARNING - Override this method when the URL path may contain secrets or PII + + Args: + response: A :class:`requests.Response` object. + + Returns: + str: The error message + """ + full_path = urlparse(response.url).path or self.path + error_type = ( + "Client" + if HTTPStatus.BAD_REQUEST + <= response.status_code + < HTTPStatus.INTERNAL_SERVER_ERROR + else "Server" + ) + + return ( + f"{response.status_code} {error_type} Error: " + f"{response.reason} for path: {full_path}." + f"Response: {response.json()}" + )