5757 LastExportDetailSerializer ,
5858 SageIntacctCredentialSerializer ,
5959)
60+ from apps .workspaces .enums import SystemCommentSourceEnum , SystemCommentIntentEnum , SystemCommentReasonEnum , SystemCommentEntityTypeEnum
61+ from apps .workspaces .system_comments import add_system_comment
62+ from fyle_accounting_library .system_comments .models import SystemComment
6063
6164
6265User = get_user_model ()
@@ -415,6 +418,7 @@ def handle_sage_intacct_rest_api_connection(
415418 :param si_user_password: Sage Intacct user password
416419 :return: None
417420 """
421+ system_comments = []
418422 try :
419423 sage_intacct_credentials = SageIntacctCredential .objects .filter (workspace = workspace ).first ()
420424
@@ -472,6 +476,16 @@ def handle_sage_intacct_rest_api_connection(
472476
473477 except SageIntacctRestInvalidTokenError as e :
474478 logger .info ('Something went wrong while connecting to Sage Intacct - %s' , e .response )
479+ add_system_comment (
480+ system_comments = system_comments ,
481+ source = SystemCommentSourceEnum .HANDLE_SAGE_INTACCT_REST_API_CONNECTION ,
482+ intent = SystemCommentIntentEnum .CONNECTION_FAILED ,
483+ entity_type = None ,
484+ workspace_id = workspace .id ,
485+ entity_id = None ,
486+ reason = 'Sage Intacct REST API connection failed: Invalid token error' ,
487+ info = {'error' : str (e .response ), 'error_type' : 'InvalidTokenError' }
488+ )
475489 return Response (
476490 {
477491 'message' : e .response
@@ -481,6 +495,16 @@ def handle_sage_intacct_rest_api_connection(
481495
482496 except SageIntacctRESTBadRequestError as e :
483497 logger .info ('Something went wrong while connecting to Sage Intacct - %s' , e .response )
498+ add_system_comment (
499+ system_comments = system_comments ,
500+ source = SystemCommentSourceEnum .HANDLE_SAGE_INTACCT_REST_API_CONNECTION ,
501+ intent = SystemCommentIntentEnum .CONNECTION_FAILED ,
502+ entity_type = None ,
503+ workspace_id = workspace .id ,
504+ entity_id = None ,
505+ reason = 'Sage Intacct REST API connection failed: Bad request error' ,
506+ info = {'error' : str (e .response ), 'error_type' : 'BadRequestError' }
507+ )
484508 return Response (
485509 {
486510 'message' : e .response
@@ -489,12 +513,25 @@ def handle_sage_intacct_rest_api_connection(
489513 )
490514 except SageIntacctRESTInternalServerError as e :
491515 logger .info ('Something went wrong while connecting to Sage Intacct - %s' , e .response )
516+ add_system_comment (
517+ system_comments = system_comments ,
518+ source = SystemCommentSourceEnum .HANDLE_SAGE_INTACCT_REST_API_CONNECTION ,
519+ intent = SystemCommentIntentEnum .CONNECTION_FAILED ,
520+ entity_type = None ,
521+ workspace_id = workspace .id ,
522+ entity_id = None ,
523+ reason = 'Sage Intacct REST API connection failed: Internal server error' ,
524+ info = {'error' : str (e .response ), 'error_type' : 'InternalServerError' }
525+ )
492526 return Response (
493527 {
494528 'message' : 'Something went wrong while connecting to Sage Intacct'
495529 },
496530 status = status .HTTP_401_UNAUTHORIZED
497531 )
532+ finally :
533+ if system_comments :
534+ SystemComment .bulk_create_comments (system_comments )
498535
499536 def handle_sage_intacct_soap_api_connection (
500537 self ,
0 commit comments