Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add loggers for GET and DELETE requests #222

Merged
Merged
22 changes: 17 additions & 5 deletions connectors/travelperk/apis/api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Loading