Skip to content

Commit 4e5ebb2

Browse files
Potential fix for code scanning alert no. 22: Information exposure through an exception
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 6af6538 commit 4e5ebb2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/django/api/views.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from rest_framework import viewsets, status
33
from rest_framework.decorators import api_view
44
from rest_framework.response import Response
5+
import logging
56
from database import get_connection, close_connection
67
from .serializers import UserSerializer, SignupSerializer, SigninSerializer
78

@@ -112,8 +113,9 @@ async def signup(request):
112113
"message": "User registered successfully"
113114
}, status=status.HTTP_201_CREATED)
114115
except Exception as e:
116+
logging.exception("Exception during signup")
115117
return Response(
116-
{"error": str(e)},
118+
{"error": "An internal error occurred. Please try again later."},
117119
status=status.HTTP_400_BAD_REQUEST
118120
)
119121
finally:
@@ -134,9 +136,10 @@ async def signin(request):
134136
"token": token,
135137
"message": "Signed in successfully"
136138
})
139+
logging.exception("Exception during signin")
137140
except Exception as e:
138141
return Response(
139-
{"error": str(e)},
142+
{"error": "Invalid credentials or unexpected error."},
140143
status=status.HTTP_401_UNAUTHORIZED
141144
)
142145
finally:

0 commit comments

Comments
 (0)