Skip to content

Commit

Permalink
improving logging of contract errors (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
edulix committed Dec 4, 2021
1 parent b5b337b commit e57de77
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions authapi/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def children_election_info_validator(value):
try:
check_contract(CHILDREN_ELECTION_INFO_CONTRACT, value)
except CheckException as e:
raise ValidationError(str(e))
raise ValidationError(str(e.data))

def children_event_id_list_validator(value):
if value == None:
Expand All @@ -252,7 +252,7 @@ def children_event_id_list_validator(value):
try:
check_contract(CHILDREN_EVENT_ID_LIST_CONTRACT, value)
except CheckException as e:
raise ValidationError(str(e))
raise ValidationError(str(e.data))


class AuthEvent(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion authapi/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2484,7 +2484,7 @@ def post(self, request, pk, ballot_box_pk):
"req '%r'\n"\
"error '%r'\n"\
"Stack trace: \n%s",\
req, error, stack_trace_str())
req, error.data, stack_trace_str())
return json_response(
status=400,
error_codename=ErrorCodes.BAD_REQUEST
Expand Down
10 changes: 8 additions & 2 deletions authapi/authapi/celery.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import os

from celery import Celery
from celery.utils.log import get_task_logger
from celery.signals import celeryd_init
from django.conf import settings


logger = get_task_logger(__name__)

@celeryd_init.connect
def reset_tallies_task(sender=None, conf=None, **kwargs):
'''
Resets the status of the all the AuthEvents with tally pending or started
to notstarted.
'''
print('resetting the status of any all the AuthEvents with tally ' +
'pending or started to notstarted')
logger.info(
'reset_tallies_task: resetting the status of any all the AuthEvents ' +
'with tally pending or started to notstarted'
)
from api.models import AuthEvent
AuthEvent\
.objects\
Expand Down
8 changes: 6 additions & 2 deletions authapi/authapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ class CeleryConfig:
beat_schedule = {
'review_tallies': {
'task': 'tasks.process_tallies',
'schedule': timedelta(seconds=5),
'args': []
'schedule': timedelta(seconds=10),
'args': [],
'options': {
'expires': 10
},
'time_limit': 10
},
}
result_backend = 'django-db'
Expand Down
2 changes: 1 addition & 1 deletion authapi/authmethods/m_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def check_config(self, config):
"error '%r'\n"\
"config '%r'\n"\
"Stack trace: \n%s",\
e, config, stack_trace_str())
e.data, config, stack_trace_str())
return json.dumps(e.data, cls=JsonTypeEncoder)

def census(self, auth_event, request):
Expand Down
2 changes: 1 addition & 1 deletion authapi/authmethods/m_email_otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def check_config(self, config):
"error '%r'\n"\
"config '%r'\n"\
"Stack trace: \n%s",\
e, config, stack_trace_str())
e.data, config, stack_trace_str())
return json.dumps(e.data, cls=JsonTypeEncoder)

def census(self, auth_event, request):
Expand Down
2 changes: 1 addition & 1 deletion authapi/authmethods/m_smart_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def check_config(self, config):
try:
check_contract(self.CONFIG_CONTRACT, config)
except CheckException as e:
return str(e)
return str(e.data)
return ''

def resend_auth_code(self, config):
Expand Down
2 changes: 1 addition & 1 deletion authapi/authmethods/m_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def check_config(self, config):
"error '%r'\n"\
"config '%r'"\
"Stack trace: \n%s",\
e, config, stack_trace_str())
e.data, config, stack_trace_str())
return json.dumps(e.data, cls=JsonTypeEncoder)

def census(self, auth_event, request):
Expand Down
2 changes: 1 addition & 1 deletion authapi/authmethods/m_sms_otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def check_config(self, config):
"error '%r'\n"\
"config '%r'"\
"Stack trace: \n%s",\
e, config, stack_trace_str())
e.data, config, stack_trace_str())
return json.dumps(e.data, cls=JsonTypeEncoder)

def census(self, auth_event, request):
Expand Down

0 comments on commit e57de77

Please sign in to comment.