Skip to content

Commit

Permalink
fix: add loggers for GET and DELETE requests (#222)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
1 parent 45c567f commit e8f90ed
Showing 1 changed file with 17 additions and 5 deletions.
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

0 comments on commit e8f90ed

Please sign in to comment.