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,17 +85,6 @@ async def create_ticket_attachment(request: Request,
try:
token = request.headers['Authorization']
is_token_valid = await validate_jwt_token(token.replace('Bearer ','').strip())
except KeyError as ke:
logger.info(f"Missing token in header")
response.status_code = 401
error_message = "Missing token in header"
except ExpiredSignatureError as ese:
error_message = ese
logger.debug(f"{ese}")
except Exception as ex:
error_message = ex
logger.debug(f"{ex}")
if is_token_valid:
ticket_data = {
"name": name,
......@@ -112,9 +101,21 @@ async def create_ticket_attachment(request: Request,
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_payload = {"error" : {"code" : 401, "message" : error_message}}
response.content = response_payload
response.content_type = 'application/json'
response.status_code = 401
error_message = "Token Invalid"
except KeyError as ke:
response.status_code = 401
error_message = ke
logger.debug(f"{ke}")
except ExpiredSignatureError as ese:
response.status_code = 401
error_message = ese
logger.debug(f"{ese}")
except Exception as ex:
response.status_code = 500
error_message = ex
logger.debug(f"{ex}")
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