Skip to content

Commit

Permalink
Add loggers for exceptions (#30)
Browse files Browse the repository at this point in the history
* Add loggers for exceptions

* fix lint
  • Loading branch information
ashwin1111 authored Feb 22, 2023
1 parent 9338656 commit 63ac083
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion fyle_rest_auth/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
import traceback
from typing import Dict

from rest_framework.exceptions import ValidationError
Expand All @@ -13,6 +15,9 @@

auth = AuthUtils()

logger = logging.getLogger(__name__)
logger.level = logging.INFO


def validate_code_and_login(request):
authorization_code = request.data.get('code')
Expand Down Expand Up @@ -53,7 +58,12 @@ def validate_code_and_login(request):

return tokens

except ValidationError as error:
logger.info(error)
raise

except Exception as error:
logger.error(traceback.format_exc())
raise ValidationError(error)


Expand Down Expand Up @@ -103,7 +113,12 @@ def validate_refresh_token_and_login(request):

return tokens

except ValidationError as error:
logger.info(error)
raise

except Exception as error:
logger.error(traceback.format_exc())
raise ValidationError(error)


Expand Down Expand Up @@ -135,7 +150,12 @@ def validate_and_refresh_token(request):

return tokens

except ValidationError as error:
logger.info(error)
raise

except Exception as error:
logger.error(traceback.format_exc())
raise ValidationError(error)


Expand Down Expand Up @@ -166,4 +186,4 @@ def get_fyle_admin(access_token: str, origin_address: str = None) -> Dict:
settings.FYLE_REST_AUTH_SERIALIZERS['FYLE_MODULE'] == 'PARTNER_DASHBOARD'):
return employee_detail
else:
raise Exception('User is not an admin')
raise ValidationError('User is not an admin')
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='fyle-rest-auth',
version='1.4.0',
version='1.5.0',
author='Shwetabh Kumar',
author_email='[email protected]',
description='Django application to implement OAuth 2.0 using Fyle in Django rest framework',
Expand Down

0 comments on commit 63ac083

Please sign in to comment.