From e8f90ed599f14b92c59a8aa0e52a60cb92edbd4a Mon Sep 17 00:00:00 2001 From: Viswas Haridas <37623357+JustARatherRidiculouslyLongUsername@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:32:05 +0530 Subject: [PATCH] fix: add loggers for GET and DELETE requests (#222) * fix: travelperk not loading all invoice profiles integrate with the travelperk pagination API to fetch invoice profiles from all pages * refactor: move `get_all_generator` to `ApiBase` and rename variable * fix: generalise the `get_all_generator` method for all onject types and create an implementation in `InvoiceProfiles` * refactor: clarity * fix: apply travelperk sync fix to all existing accounts * test: add request and response logs to the travelperk api * fix: add loggers for GET and DELETE requests as well --- connectors/travelperk/apis/api_base.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/connectors/travelperk/apis/api_base.py b/connectors/travelperk/apis/api_base.py index c110a9d..7747d13 100644 --- a/connectors/travelperk/apis/api_base.py +++ b/connectors/travelperk/apis/api_base.py @@ -66,17 +66,24 @@ def _get_request(self, object_type: str, api_url: str, params: dict = {}) -> Lis 'Api-Version': '1' } + endpoint = '{0}{1}'.format(self.__server_url, api_url) + logger.debug(f"GET {endpoint}") + logger.debug(f"Params for GET request: {params}") response = requests.get( - '{0}{1}'.format(self.__server_url, api_url), + endpoint, headers=api_headers, params=params ) if response.status_code == 200: result = json.loads(response.text) + logger.debug(f"GET response: {result}") return result[object_type] else: - raise self._get_error(response.status_code, response.text) + error = self._get_error(response.status_code, response.text) + logger.info(f"GET request failed: {response.status_code} | {error.message}") + logger.info(f"GET response: {error.response}") + raise error def _get_all_generator(self, object_type: str, api_url: str): """ @@ -154,13 +161,18 @@ def _delete_request(self, api_url: str) -> Dict: 'Api-Version': '1' } + endpoint = '{0}{1}'.format(self.__server_url, api_url) + logger.debug(f"DELETE {endpoint}") response = requests.delete( - '{0}{1}'.format(self.__server_url, api_url), + endpoint, headers=api_headers ) if response.status_code == 200: + logger.debug(f"DELETE response: {response.text}") return response.text - else: - raise self._get_error(response.status_code, response.text) + error = self._get_error(response.status_code, response.text) + logger.info(f"DELETE request failed: {response.status_code} | {error.message}") + logger.info(f"DELETE response: {error.response}") + raise error