From d0511f46c01e63fe6a103d8050b90e3b4b41df7b Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 5 Apr 2023 17:07:02 -0500 Subject: [PATCH] Fix bug --- judge/middleware.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/judge/middleware.py b/judge/middleware.py index 999678c..1c7f18a 100644 --- a/judge/middleware.py +++ b/judge/middleware.py @@ -156,18 +156,21 @@ class SlowRequestMiddleware(object): start_time = time.time() response = self.get_response(request) if response.status_code == 200: - response_time = time.time() - start_time - url_name = resolve(request.path).url_name - message = { - "url_name": url_name, - "response_time": response_time * 1000, - "profile": request.user.username, - "date": datetime.now().strftime("%Y/%m/%d"), - "url": request.build_absolute_uri(), - "method": request.method, - } - if response_time > 9: - logger_slow.info(json.dumps(message)) - if random.random() < 0.1: - logger.info(json.dumps(message)) + try: + response_time = time.time() - start_time + url_name = resolve(request.path).url_name + message = { + "url_name": url_name, + "response_time": response_time * 1000, + "profile": request.user.username, + "date": datetime.now().strftime("%Y/%m/%d"), + "url": request.build_absolute_uri(), + "method": request.method, + } + if response_time > 9: + logger_slow.info(json.dumps(message)) + if random.random() < 0.1: + logger.info(json.dumps(message)) + except Exception: + pass return response