-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
183 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import logging | ||
|
||
from fyle.platform.exceptions import NoPrivilegeError, RetryException, InvalidTokenError as FyleInvalidTokenError | ||
from rest_framework.response import Response | ||
from rest_framework.views import status | ||
|
||
from apps.workspaces.models import FyleCredential, Workspace, ExportSettings, AdvancedSetting | ||
from apps.tasks.models import AccountingExport | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.level = logging.INFO | ||
|
||
|
||
def handle_view_exceptions(): | ||
def decorator(func): | ||
def new_fn(*args, **kwargs): | ||
try: | ||
return func(*args, **kwargs) | ||
except AccountingExport.DoesNotExist: | ||
return Response(data={'message': 'AccountingExport not found'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except FyleCredential.DoesNotExist: | ||
return Response(data={'message': 'Fyle credentials not found in workspace'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except FyleInvalidTokenError as exception: | ||
logger.info('Fyle token expired workspace_id - %s %s', kwargs['workspace_id'], {'error': exception.response}) | ||
return Response(data={'message': 'Fyle token expired workspace_id'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except NoPrivilegeError as exception: | ||
logger.info('Invalid Fyle Credentials / Admin is disabled for workspace_id%s %s', kwargs['workspace_id'], {'error': exception.response}) | ||
return Response(data={'message': 'Invalid Fyle Credentials / Admin is disabled'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except RetryException: | ||
logger.info('Fyle Retry Exception for workspace_id %s', kwargs['workspace_id']) | ||
return Response(data={'message': 'Fyle API rate limit exceeded'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except Workspace.DoesNotExist: | ||
return Response(data={'message': 'Workspace with this id does not exist'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except AdvancedSetting.DoesNotExist: | ||
return Response(data={'message': 'Advanced Settings does not exist in workspace'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except ExportSettings.DoesNotExist: | ||
return Response({'message': 'Export Settings does not exist in workspace'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
except Exception as exception: | ||
logger.exception(exception) | ||
return Response(data={'message': 'An unhandled error has occurred, please re-try later'}, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
return new_fn | ||
|
||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from django.urls import path | ||
|
||
from apps.fyle.views import SyncFyleDimensionView | ||
from apps.fyle.views import SyncFyleDimensionView, WebhookCallbackView | ||
|
||
|
||
urlpatterns = [ | ||
path('sync_dimensions/', SyncFyleDimensionView.as_view(), name='sync-fyle-dimensions'), | ||
path('webhook_callback/', WebhookCallbackView.as_view(), name='webhook-callback'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Create admin subscriptions for existing workspaces | ||
|
||
from apps.workspaces.tasks import async_create_admin_subcriptions | ||
from apps.workspaces.models import Workspace | ||
|
||
workspaces = Workspace.objects.filter(onboarding_state='COMPLETE').all() | ||
|
||
for workspace in workspaces: | ||
try: | ||
async_create_admin_subcriptions(workspace.id) | ||
except Exception as e: | ||
print('Error while creating admin subscriptions for workspace - {} with ID - {}'.format(workspace.name, workspace.id)) | ||
print(e.__dict__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters