Skip to content

Commit

Permalink
Error log changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sathyababuram K committed Mar 6, 2024
1 parent 188a20e commit bfe858e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions SmartApi/smartConnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, api_key=None, access_token=None, refresh_token=None,feed_toke
log_folder_path = os.path.join("logs", log_folder) # Construct the full path to the log folder
os.makedirs(log_folder_path, exist_ok=True) # Create the log folder if it doesn't exist
log_path = os.path.join(log_folder_path, "app.log") # Construct the full path to the log file
logzero.logfile(log_path, loglevel=logging.INFO) # Output logs to a date-wise log file
logzero.logfile(log_path, loglevel=logging.ERROR) # Output logs to a date-wise log file

if pool:
self.reqsession = requests.Session()
Expand Down Expand Up @@ -207,6 +207,7 @@ def _request(self, route, method, parameters=None):
proxies=self.proxies)

except Exception as e:
logger.error(f"Error occurred while making a {method} request to {url}. Error: {str(e)}")
raise e

if self.debug:
Expand All @@ -230,7 +231,8 @@ def _request(self, route, method, parameters=None):
# native errors
exp = getattr(ex, data["error_type"], ex.GeneralException)
raise exp(data["message"], code=r.status_code)

if data.get("success",False) is False :
logger.error(f"Error occurred while making a {method} request to {url}. Error: {data['message']}. URL: {url}, Headers: {headers}, Request: {params}, Response: {data}")
return data
elif "csv" in headers["Content-type"]:
return r.content
Expand Down

0 comments on commit bfe858e

Please sign in to comment.