Improve error handling in CaptchaWidget by logging session details when captcha is not found

1 parent f34bd454
...@@ -406,11 +406,14 @@ class CaptchaWidget(Widget): ...@@ -406,11 +406,14 @@ class CaptchaWidget(Widget):
_logging.error(f"Captcha tidak sesuai: {pstruct} != {captcha_session}") _logging.error(f"Captcha tidak sesuai: {pstruct} != {captcha_session}")
raise Invalid(field.schema, captcha_message) raise Invalid(field.schema, captcha_message)
else: else:
captcha_file = os.path.join(settings['captcha_files'], f"{pstruct}.png") # captcha_file = os.path.join(settings['captcha_files'], f"{pstruct}.png")
captcha_exists = os.path.exists(captcha_file) # captcha_exists = os.path.exists(captcha_file)
if not captcha_exists: # if not captcha_exists:
_logging.error(f"Captcha file not found: {captcha_file}") # _logging.error(f"Captcha file not found: {captcha_file}")
raise Invalid(field.schema, captcha_message) _logging.error(f"Captcha session not found for input: {pstruct}")
_logging.error(self.request.session.items())
raise Invalid(field.schema, captcha_message)
return pstruct return pstruct
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!