Improved error handling and consolidation on ticket purchase flow
This commit is contained in:
parent
e1221d4c45
commit
6d8b457593
6 changed files with 43 additions and 47 deletions
|
|
@ -11,18 +11,14 @@ from core.observers.BaseObserver import BaseObserver
|
|||
from core.services.payment_phase.save_and_send_intitial_billing import save_and_send_intitial_billing
|
||||
from core.services.networking.api_requests.ApiResponseModel import ApiResponse, ErrorType
|
||||
from core.models.Result import Result, ResultError
|
||||
from core.services.networking.api_requests.step5_solve_api_problems import solve_api_problems
|
||||
from core.errors.logger import logger
|
||||
# from core.errors.exceptions import NetworkingError
|
||||
|
||||
from core.services.prepare_tickets.ticket_tracker import does_ticket_tracker_exist
|
||||
from core.services.prepare_tickets.setup_ticket_tracker import setup_ticket_tracker
|
||||
# from core.services.networking.api_requests.step1_get_or_post import send_data_to_server
|
||||
from core.services.networking.httpx import connect
|
||||
|
||||
|
||||
from core.services.networking.make_url import make_url
|
||||
# from core.utils.confirm_its_a_valid_key_choice import confirm_its_a_valid_key_choice
|
||||
from core.services.helpers.valid_profile_quantity import valid_profile_quantity
|
||||
from core.errors.exceptions import *
|
||||
from core.controllers.tickets.TicketSyncController import sync_ticket_prices
|
||||
|
|
@ -122,8 +118,6 @@ def initiate_payment(
|
|||
except ValueError as e:
|
||||
if ticket_observer:
|
||||
ticket_observer.notify("failed_input", subject=str(e))
|
||||
# invoice_data_object.add_error_code("invalid_data")
|
||||
# return invoice_data_object
|
||||
return Result(valid=False, error_type=ResultError.INVALID_INPUT, message=str(e))
|
||||
|
||||
except ConnectionError as e:
|
||||
|
|
@ -131,24 +125,8 @@ def initiate_payment(
|
|||
logger.error(error_msg, exc_info=True)
|
||||
if ticket_observer:
|
||||
ticket_observer.notify("connection_error", subject=str(e))
|
||||
# invoice_data_object.add_error_code("connection_error")
|
||||
return Result(valid=False, error_type=ResultError.CONNECTION, message=error_msg)
|
||||
|
||||
# except ServerSideError as e:
|
||||
# error_msg = f"ServerSideError: {e}"
|
||||
# logger.error(error_msg, exc_info=True)
|
||||
# ticket_observer.notify("failed_output", subject=error_msg)
|
||||
# invoice_data_object.add_error_code("server_error")
|
||||
# return invoice_data_object
|
||||
|
||||
# except Exception as e:
|
||||
# error_msg = f"Error: {e}"
|
||||
# logger.error(error_msg, exc_info=True)
|
||||
# ticket_observer.notify("unknown_error", subject=error_msg)
|
||||
# invoice_data_object.add_error_code("unknown_error")
|
||||
# return invoice_data_object
|
||||
###############
|
||||
|
||||
|
||||
def check_if_paid(
|
||||
temp_billing_code: str,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
from core.utils.basic_operations.write_or_read_from_json import get_value_from_json_file
|
||||
from core.Constants import Constants
|
||||
# from core.utils.basic_operations.write_or_read_from_json import get_value_from_json_file
|
||||
# from core.Constants import Constants
|
||||
|
||||
|
||||
def get_which_billing_key() -> str:
|
||||
billing_folder = Constants.HV_TICKETING_CONFIG_HOME
|
||||
filepath = f"{billing_folder}/billing_choices.json"
|
||||
# def get_which_billing_key() -> str:
|
||||
# billing_folder = Constants.HV_TICKETING_CONFIG_HOME
|
||||
# filepath = f"{billing_folder}/billing_choices.json"
|
||||
|
||||
json_key = "which_key"
|
||||
which_key = get_value_from_json_file(filepath, json_key)
|
||||
return which_key
|
||||
# json_key = "which_key"
|
||||
# which_key = get_value_from_json_file(filepath, json_key)
|
||||
# return which_key
|
||||
|
||||
|
||||
|
||||
# Function moved to 'ticket_config_tools' module. This is commented out until confirmed stable later.
|
||||
|
|
@ -1,16 +1,32 @@
|
|||
from core.utils.basic_operations.write_or_read_from_json import get_value_from_json_file
|
||||
from core.Constants import Constants
|
||||
from core.errors.logger import logger
|
||||
|
||||
billing_folder = Constants.HV_TICKETING_CONFIG_HOME
|
||||
billing_config = f"{billing_folder}/billing_choices.json"
|
||||
|
||||
def do_we_have_billing_id() -> str | None:
|
||||
try:
|
||||
billing_folder = Constants.HV_TICKETING_CONFIG_HOME
|
||||
filepath = f"{billing_folder}/billing_choices.json"
|
||||
|
||||
billing_id = get_value_from_json_file(filepath, "temp_billing_code")
|
||||
billing_id = get_value_from_json_file(billing_config, "temp_billing_code")
|
||||
if billing_id == "":
|
||||
return None
|
||||
|
||||
return billing_id
|
||||
|
||||
except:
|
||||
except ValueError as e:
|
||||
logger.error(f"We can't open the config, because the input values are incorrect type or form. {e}.")
|
||||
return False
|
||||
except KeyError as e:
|
||||
logger.error(f"The requested value was not found. {e}.")
|
||||
return None
|
||||
|
||||
|
||||
def get_which_billing_key() -> str:
|
||||
try:
|
||||
return get_value_from_json_file(billing_config, "which_key")
|
||||
except ValueError as e:
|
||||
logger.error(f"We can't open the config to get which_key, because the input values are incorrect type or form. {e}.")
|
||||
return False
|
||||
except KeyError as e:
|
||||
logger.error(f"The requested value of 'which_key' was not found. {e}.")
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -5,18 +5,15 @@ if TYPE_CHECKING:
|
|||
from essentials.observers.ConnectionObserver import ConnectionObserver
|
||||
from core.observers.TicketObserver import TicketObserver
|
||||
# services
|
||||
# from core.services.networking.api_requests.step1_get_or_post import send_data_to_server
|
||||
from core.services.networking.httpx import connect
|
||||
from core.services.networking.api_requests.ApiResponseModel import ApiResponse, ErrorType
|
||||
# from core.services.networking.api_requests.step5_solve_api_problems import solve_api_problems
|
||||
from core.services.networking.make_url import make_url
|
||||
from core.services.helpers.get_which_billing_key import get_which_billing_key
|
||||
# from core.services.payment_phase.ticket_config_tools import get_which_billing_key
|
||||
|
||||
# models & their controllers
|
||||
from core.models.session.SessionProfile import SessionProfile
|
||||
from core.models.system.SystemProfile import SystemProfile
|
||||
from core.models.Subscription import Subscription # not sure if needed
|
||||
# from core.controllers.ProfileController import ProfileController
|
||||
|
||||
# utils
|
||||
from core.utils.basic_operations.write_or_read_from_json import get_value_from_json_file
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ from core.services.networking.api_requests.ApiResponseModel import ApiResponse,
|
|||
from core.services.networking.api_requests.step5_solve_api_problems import solve_api_problems
|
||||
|
||||
from core.services.networking.make_url import make_url
|
||||
from core.services.helpers.get_which_billing_key import get_which_billing_key
|
||||
from core.services.payment_phase.ticket_config_tools import get_which_billing_key
|
||||
|
||||
# utils
|
||||
from core.utils.get_raw_string import get_raw_string
|
||||
# errors & generic
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ def get_value_from_json_file(filepath: str, key: str, category: str | None = Non
|
|||
data = read_entire_json(filepath)
|
||||
|
||||
if category:
|
||||
if isinstance(category, bool):
|
||||
error_msg = f"Error in get_value_from_json_file, category should not be a boolean: {category}"
|
||||
if not isinstance(category, str):
|
||||
error_msg = f"Error in get_value_from_json_file, category must be a string, not {type(category)}: {category}"
|
||||
logger.error(error_msg)
|
||||
raise ValueError(error_msg)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue