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

Logging, Exception Management Assignment #30

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

ritam-ti
Copy link

No description provided.

Copy link

@naman-TI naman-TI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approved, many changes to be made.

@@ -15,6 +15,7 @@

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

info logs missing throughout the file

@@ -12,4 +12,6 @@


def get_enriched_lead_json(adf_json: dict) -> dict:
if adf_json == {}:
logging.warning("Empty JSON")
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise KeyError for missing 'adf' key and check if adj_json is valid to raise ValueError

@@ -17,10 +17,16 @@ async def reset_authkey(request: Request, token: str = Depends(get_token)):
body = json.loads(body)
provider, role = get_user_role(token)
if role != "ADMIN" and (role != "3PL"):
logging.info("Role is neither Admin nor 3PL")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise http exception with proper status code, add info logs where necessary

@@ -47,6 +48,7 @@ async def submit(file: Request, apikey: APIKey = Depends(get_api_key)):

# check if xml was not parsable, if not return
if not obj:
logging.error("XML could not be parsed")
provider = db_helper_session.get_api_key_author(apikey)
obj = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try except for line 59

@@ -95,11 +99,13 @@ async def submit(file: Request, apikey: APIKey = Depends(get_api_key)):
for future in as_completed(futures):
result = future.result()
if result.get('Duplicate_Api_Call', {}).get('status', False):
logging.warning("Duplicate API call")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log info for the time taken for request completion

@@ -199,6 +211,7 @@ async def submit(file: Request, apikey: APIKey = Depends(get_api_key)):
res = sqs_helper_session.send_message(message)

else:
logging.info("Rejected current response")
message = {
'put_file': {
'item': item,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 226 try except block

# throw proper HTTPException
pass
logging.error("Lead conversion not updated")
raise HTTPException(status_code = 406, detail = "Lead conversion not updated")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*already updated, status_code should be 400

@@ -355,3 +355,9 @@ def verify_response(response_code):

session = get_boto3_session()
db_helper_session = DBHelper(session)


def log_res_data(obj : DBHelper):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this function called?

@ritam-ti
Copy link
Author

Kindly check the current changes and suggest any if needed

logging.info("Role is neither Admin nor 3PL")
pass
logging.error("Role required to be admin or 3PL")
raise HTTPException(status_code = 400, detail = "Role required to be admin or 3PL")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

400 status code is for a Bad request.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decide whether this should be 401 or 403.

@naman-TI
Copy link

This is Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants