Handle more errors

Internal Server Error: /ipv6/work/signup/
Traceback (most recent call last):
  File "/home/app/pyvenv/lib/python3.5/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/app/pyvenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/app/pyvenv/lib/python3.5/site-packages/django/core/handlers/base.py", line 124, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "./users/views.py", line 19, in signup
    create_user(username, raw_password, first_name, last_name, email)
  File "./users/ldap_funcs.py", line 18, in create_user
    uidNumber = get_max_uid() + 1
  File "./users/ldap_funcs.py", line 79, in get_max_uid
    return int(handler.read())
ValueError: invalid literal for int() with base 10: ''
This commit is contained in:
PCoder 2019-02-03 14:04:04 +01:00
parent 506679b8a0
commit 2196390d7a

View file

@ -76,9 +76,21 @@ def get_max_uid():
"""
try:
with open(settings.LDAP_MAX_UID_PATH, 'r+') as handler:
return int(handler.read())
try:
return_value = int(handler.read())
except ValueError as ve:
logger.error(
"Error reading int value from {}. {}"
"Returning default value {} instead".format(
settings.LDAP_MAX_UID_PATH,
str(ve),
settings.LDAP_DEFAULT_START_UID
)
)
return_value = settings.LDAP_DEFAULT_START_UID
return return_value
except FileNotFoundError as fnfe:
logger.error("File not found : " + str(fnfe))
ret = settings.LDAP_DEFAULT_START_UID
logger.error("So, returing UID={}".format(ret))
return ret
retrun_value = settings.LDAP_DEFAULT_START_UID
logger.error("So, returning UID={}".format(retrun_value))
return retrun_value