Commit f9b21016 authored by Kamal Dodiya's avatar Kamal Dodiya
Browse files

Send 500 for server error

parent 7e05edfd
Pipeline #185790 passed with stages
in 1 minute and 44 seconds
...@@ -85,36 +85,37 @@ async def create_ticket_attachment(request: Request, ...@@ -85,36 +85,37 @@ async def create_ticket_attachment(request: Request,
try: try:
token = request.headers['Authorization'] token = request.headers['Authorization']
is_token_valid = await validate_jwt_token(token.replace('Bearer ','').strip()) is_token_valid = await validate_jwt_token(token.replace('Bearer ','').strip())
if is_token_valid:
ticket_data = {
"name": name,
"email": email,
"subject": subject,
"message": message,
"files": files,
"request": request,
"date" : datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
}
email_success = await mail_manager.send_email_wtih_attachment_async(ticket_data)
if email_success:
response = TicketResponse()
response.success = True
else:
response.status_code = 500
error_message = "Could not send email"
logger.debug(f"Could not send email and RT is not created")
else:
response.status_code = 401
error_message = "Token Invalid"
except KeyError as ke: except KeyError as ke:
logger.info(f"Missing token in header")
response.status_code = 401 response.status_code = 401
error_message = "Missing token in header" error_message = ke
logger.debug(f"{ke}")
except ExpiredSignatureError as ese: except ExpiredSignatureError as ese:
response.status_code = 401
error_message = ese error_message = ese
logger.debug(f"{ese}") logger.debug(f"{ese}")
except Exception as ex: except Exception as ex:
response.status_code = 500
error_message = ex error_message = ex
logger.debug(f"{ex}") logger.debug(f"{ex}")
if is_token_valid:
ticket_data = {
"name": name,
"email": email,
"subject": subject,
"message": message,
"files": files,
"request": request,
"date" : datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
}
email_success = await mail_manager.send_email_wtih_attachment_async(ticket_data)
if email_success:
response = TicketResponse()
response.success = True
else:
response.status_code = 500
else:
response_payload = {"error" : {"code" : 401, "message" : error_message}}
response.content = response_payload
response.content_type = 'application/json'
response.status_code = 401
return response return response
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment