mirror of https://github.com/zulip/zulip.git
middleware: Improve logging of users causing 40x errors.
Previously we only got the user ID for /json requests, not /api requests, and also only got the user ID, not the email address. (imported from commit c3625f9c1a48430e35183be6c90a7855f3714948)
This commit is contained in:
parent
4cd3fd234c
commit
a3a0880266
|
@ -76,6 +76,7 @@ def authenticated_api_view(view_func):
|
|||
if api_key != user_profile.api_key:
|
||||
return json_error("Invalid API key for user '%s'" % (email,))
|
||||
request._client = client
|
||||
request._email = email
|
||||
update_user_activity(request, user_profile, client)
|
||||
return view_func(request, user_profile, *args, **kwargs)
|
||||
return _wrapped_view_func
|
||||
|
@ -90,6 +91,7 @@ def authenticate_log_and_execute_json(request, client, view_func, *args, **kwarg
|
|||
user_profile = get_tornado_user_profile(request.user.id)
|
||||
else:
|
||||
user_profile = UserProfile.objects.select_related().get(user=request.user)
|
||||
request._email = user_profile.user.email
|
||||
update_user_activity(request, user_profile, client)
|
||||
return view_func(request, user_profile, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ class LogRequests(object):
|
|||
# Log some additional data whenever we return a 40x error
|
||||
if 400 <= response.status_code < 500:
|
||||
try:
|
||||
user_id = request.user.id
|
||||
email = request._email
|
||||
except:
|
||||
user_id = "unknown"
|
||||
logger.info('status=%3d, data=%s, uid=%s' % (response.status_code, response.content, user_id))
|
||||
email = "unknown"
|
||||
logger.info('status=%3d, data=%s, uid=%s' % (response.status_code, response.content, email))
|
||||
return response
|
||||
|
||||
class JsonErrorHandler(object):
|
||||
|
|
Loading…
Reference in New Issue