mirror of
https://github.com/its-michaelroy/Deep-Impact.git
synced 2026-06-04 02:20:41 +00:00
Update utils.py
Fix CodeQL alerts #1 and #2: Secure exception handling in get_sentry and get_quiz 33,115
This commit is contained in:
@@ -28,9 +28,9 @@ def get_sentry():
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
return Response(data, status=HTTP_200_OK)
|
return Response(data, status=HTTP_200_OK)
|
||||||
except ValidationError as e:
|
except (requests.RequestException, json.JSONDecodeError) as e:
|
||||||
print(e)
|
logger.error(f"Error in get_sentry: {str(e)}", exc_info=True)
|
||||||
return Response(e, status=HTTP_400_BAD_REQUEST)
|
return Response({"error": "Failed to fetch Sentry data"}, status=HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -110,9 +110,9 @@ def get_quiz():
|
|||||||
print(data)
|
print(data)
|
||||||
|
|
||||||
return Response(data, status=HTTP_201_CREATED)
|
return Response(data, status=HTTP_201_CREATED)
|
||||||
except ValidationError as e:
|
except (json.JSONDecodeError, openai.OpenAIError) as e:
|
||||||
print(e)
|
logger.error(f"Error in get_quiz: {str(e)}", exc_info=True)
|
||||||
return Response(e, status=HTTP_400_BAD_REQUEST)
|
return Response({"error": "Failed to generate quiz"}, status=HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
# ask_question()
|
# ask_question()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user