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

Fix information exposure through logger #2649

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
9 changes: 7 additions & 2 deletions website/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import base64
import io
import json
import logging
import os
import re
import time
Expand Down Expand Up @@ -137,6 +138,8 @@
# Load environment variables
load_dotenv()

logger = logging.getLogger(__name__)


@login_required
def profile_edit(request):
Expand Down Expand Up @@ -4823,7 +4826,8 @@ def chatbot_conversation(request):
try:
response = crc.invoke({"question": question})
except Exception as e:
error_message = f"Error: {str(e)}"
logger.error(f"An error occurred: {str(e)}")
npxpatel marked this conversation as resolved.
Show resolved Hide resolved
error_message = "An unexpected error occurred. Please try again later"
ChatBotLog.objects.create(question=question, answer=error_message)
return Response({"error": error_message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# Increment the request count
Expand All @@ -4836,7 +4840,8 @@ def chatbot_conversation(request):
return Response({"answer": response["answer"]}, status=status.HTTP_200_OK)

except Exception as e:
error_message = f"Error: {str(e)}"
logger.error(f"An error occurred: {str(e)}")
npxpatel marked this conversation as resolved.
Show resolved Hide resolved
error_message = "An unexpected error occurred. Please try again later"
ChatBotLog.objects.create(question=request.data.get("question", ""), answer=error_message)
return Response({"error": error_message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

Expand Down
Loading