Skip to content

Commit 04bb852

Browse files
committed
Add logging to debug verification failures
1 parent 90d00a1 commit 04bb852

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

hcaptcha_field/fields.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
from urllib.error import HTTPError
34
from urllib.parse import urlencode
45
from urllib.request import build_opener, Request, ProxyHandler
@@ -11,6 +12,9 @@
1112
from hcaptcha_field.widgets import hCaptchaWidget
1213

1314

15+
LOGGER = logging.getLogger('hcaptcha_field')
16+
17+
1418
DATA_ATTRIBUTE_CONFIG = frozenset([
1519
'theme',
1620
'size',
@@ -114,6 +118,7 @@ def validate(self, value):
114118
try:
115119
response = opener.open(request, timeout=hcaptcha_settings.TIMEOUT)
116120
except HTTPError:
121+
LOGGER.exception("Failed to verify response with hCaptcha API.")
117122
raise ValidationError(
118123
self.error_messages['error_hcaptcha'],
119124
code='error_hcaptcha'
@@ -122,6 +127,7 @@ def validate(self, value):
122127
# Check response
123128
response_data = json.loads(response.read().decode('utf-8'))
124129
if not response_data.get('success'):
130+
LOGGER.error("Failed to pass hCaptcha check: %s", response_data)
125131
raise ValidationError(
126132
self.error_messages['invalid_hcaptcha'],
127133
code='invalid_hcaptcha'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
setuptools.setup(
99
# Metadata
1010
name='django-hcaptcha-field',
11-
version='0.9',
11+
version='0.9.1',
1212
license='BSD',
1313
author='Ties Jan Hefting',
1414
author_email='hello@tiesjan.com',

0 commit comments

Comments
 (0)