From d7578d9240dd7550adc1bca477aaaa959a5da147 Mon Sep 17 00:00:00 2001 From: Gabriel Barberini Date: Fri, 15 Nov 2024 22:06:58 -0300 Subject: [PATCH] fixes controllers create logs fault tolerancy --- lib/controllers/environment.py | 7 ++++--- lib/controllers/flight.py | 7 ++++--- lib/controllers/motor.py | 7 ++++--- lib/controllers/rocket.py | 7 ++++--- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/controllers/environment.py b/lib/controllers/environment.py index fe965a5..bb2b09b 100644 --- a/lib/controllers/environment.py +++ b/lib/controllers/environment.py @@ -56,9 +56,10 @@ async def create_env(env: Env) -> Union[EnvCreated, HTTPException]: else: return EnvCreated(env_id=env_repo.env_id) finally: - logger.info( - f"Call to controllers.environment.create_env completed for Env {None or env_repo.env_id}" - ) + if env_repo: + logger.info( + f"Call to controllers.environment.create_env completed for Env {env_repo.env_id}" + ) @staticmethod async def get_env_by_id(env_id: str) -> Union[Env, HTTPException]: diff --git a/lib/controllers/flight.py b/lib/controllers/flight.py index eb07cff..245bf21 100644 --- a/lib/controllers/flight.py +++ b/lib/controllers/flight.py @@ -73,9 +73,10 @@ async def create_flight( else: return FlightCreated(flight_id=flight_repo.flight_id) finally: - logger.info( - f"Call to controllers.flight.create_flight completed for Flight {None or flight_repo.flight_id}" - ) + if flight_repo: + logger.info( + f"Call to controllers.flight.create_flight completed for Flight {flight_repo.flight_id}" + ) @staticmethod async def get_flight_by_id( diff --git a/lib/controllers/motor.py b/lib/controllers/motor.py index 37298df..10fad67 100644 --- a/lib/controllers/motor.py +++ b/lib/controllers/motor.py @@ -69,9 +69,10 @@ async def create_motor( else: return MotorCreated(motor_id=motor_repo.motor_id) finally: - logger.info( - f"Call to controllers.motor.create_motor completed for Motor {None or motor_repo.motor_id}" - ) + if motor_repo: + logger.info( + f"Call to controllers.motor.create_motor completed for Motor {motor_repo.motor_id}" + ) @staticmethod async def get_motor_by_id( diff --git a/lib/controllers/rocket.py b/lib/controllers/rocket.py index a59f551..4a7ad17 100644 --- a/lib/controllers/rocket.py +++ b/lib/controllers/rocket.py @@ -63,9 +63,10 @@ async def create_rocket( else: return RocketCreated(rocket_id=rocket_repo.rocket_id) finally: - logger.info( - f"Call to controllers.rocket.create_rocket completed for Rocket {None or rocket_repo.rocket_id}" - ) + if rocket_repo: + logger.info( + f"Call to controllers.rocket.create_rocket completed for Rocket {rocket_repo.rocket_id}" + ) @staticmethod async def get_rocket_by_id(