Skip to content

Commit

Permalink
feat: Adding extensive loggers (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Oct 14, 2024
1 parent 2adf3ec commit c0f5e75
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sage_desktop_sdk/core/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import logging
import requests
import json
from typing import List, Dict, Generator
Expand All @@ -14,6 +15,7 @@
InternalServerError
)

logger = logging.getLogger(__name__)

class Client:
"""
Expand Down Expand Up @@ -120,6 +122,8 @@ def _query_get_all_generator(self, url: str, is_paginated: bool = False) -> Gene

data = json.loads(response.text)

logger.debug('Response for get request for url: %s, %s', request_url, response.text)

if not data:
break

Expand All @@ -131,6 +135,7 @@ def _query_get_all_generator(self, url: str, is_paginated: bool = False) -> Gene
break

except requests.exceptions.HTTPError as err:
logger.info('Response for get request for url: %s, %s', url, err.response.text)
if err.response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down Expand Up @@ -162,9 +167,11 @@ def _query_get_all(self, url: str) -> List[Dict]:
response = requests.get(url=request_url, headers=api_headers)

if response.status_code == 200:
logger.debug('Response for get request for url: %s, %s', request_url, response.text)
data = json.loads(response.text)
return data

logger.info('Response for get request for url: %s, %s', url, response.text)
if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down Expand Up @@ -196,9 +203,11 @@ def _query_get_by_id(self, url: str) -> List[Dict]:
response = requests.get(url=request_url, headers=api_headers)

if response.status_code == 200:
logger.debug('Response for get request for url: %s, %s', request_url, response.text)
data = json.loads(response.text)
return data

logger.info('Response for get request for url: %s, %s', url, response.text)
if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', response.text)

Expand Down Expand Up @@ -228,10 +237,13 @@ def _post_request(self, url: str, data=None) -> Dict:
}

response = requests.post(url=request_url, headers=api_headers, data=data)
logger.debug('Payload for post request: %s', data)

if response.status_code == 200:
logger.debug('Response for post request: %s', response.text)
return json.loads(response.text)

logger.info('Response for post request: %s', response.text)
if response.status_code == 400:
raise WrongParamsError('Some of the parameters are wrong', json.loads(response.text))

Expand Down

0 comments on commit c0f5e75

Please sign in to comment.