diff --git a/cli/commands/profile.py b/cli/commands/profile.py index e5a11d3..7eac9bc 100644 --- a/cli/commands/profile.py +++ b/cli/commands/profile.py @@ -1,4 +1,4 @@ -from core.Errors import MissingSubscriptionError, InvalidSubscriptionError, ConnectionUnprotectedError, EndpointVerificationError, ProfileStateConflictError, PaymentRequiredError +from core.Errors import MissingSubscriptionError, InvalidSubscriptionError, ConnectionUnprotectedError, EndpointVerificationError, ProfileStateConflictError, PaymentRequiredError, UnknownConnectionTypeError from core.controllers.ApplicationVersionController import ApplicationVersionController from core.controllers.InvoiceController import InvoiceController from core.controllers.LocationController import LocationController @@ -184,6 +184,10 @@ def handle(arguments, main_parser): except SingboxNotInstalledException: main_parser.error('sing-box is not installed. Please run the installation script first.') + except UnknownConnectionTypeError: + print('No connection method configured. Please run:\n') + print(' python -m cli set connection system') + print(' python -m cli sync\n') except PaymentRequiredError: print('Payment processing is currently unavailable. The subscription could not be activated.\nPlease try again later or contact support.') except (InvalidSubscriptionError, MissingSubscriptionError) as exception: @@ -218,25 +222,32 @@ def _handle_subscription_error(exception, profile, ignore, arguments, main_parse subscription_plan = SubscriptionPlanController.get(profile.connection, 720) if subscription_plan is None: - raise RuntimeError('No compatible subscription plan was found. Please contact support.') + if not SubscriptionPlanController.get_all(): + print('\nData not synchronized. Please run the following commands and try again:\n') + print(' python -m cli set connection system') + print(' python -m cli sync\n') + else: + print('\nNo compatible subscription plan was found. Please contact support.\n') + return potential_subscription = SubscriptionController.create(subscription_plan, profile, connection_observer=connection_observer) if potential_subscription is None: - raise RuntimeError('The subscription could not be created. Please try again later.') + print('\nThe subscription could not be created. Please try again later.\n') + return ProfileController.attach_subscription(profile, potential_subscription) if potential_subscription.operator_id is None: subscription = InvoiceController.handle_payment(potential_subscription.billing_code, invoice_observer=invoice_observer, connection_observer=connection_observer) if subscription is None: - print('\nPayment processing is currently unavailable. Please try again later or contact support.') + print('\nPayment processing is currently unavailable. Please try again later or contact support.\n') return ProfileController.attach_subscription(profile, subscription) try: ProfileController.enable(profile, ignore=ignore, pristine=arguments.pristine, asynchronous=True, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer) except PaymentRequiredError: - print('\nPayment processing is currently unavailable. The subscription could not be activated.\nPlease try again later or contact support.') + print('\nPayment processing is currently unavailable. The subscription could not be activated.\nPlease try again later or contact support.\n') return elif manage_subscription_input == '2': @@ -248,7 +259,7 @@ def _handle_subscription_error(exception, profile, ignore, arguments, main_parse try: ProfileController.enable(profile, ignore=ignore, pristine=arguments.pristine, asynchronous=True, profile_observer=profile_observer, application_version_observer=application_version_observer, connection_observer=connection_observer) except PaymentRequiredError: - print('\nPayment processing is currently unavailable. The subscription could not be activated.\nPlease try again later or contact support.') + print('\nPayment processing is currently unavailable. The subscription could not be activated.\nPlease try again later or contact support.\n') return else: print('\nThe billing code appears to be invalid.\n')