From 08bb0e2d85232b9ba311b1f800cac3d6205082b0 Mon Sep 17 00:00:00 2001 From: Tushar <30565750+tushar5526@users.noreply.github.com> Date: Thu, 23 May 2024 03:07:02 +0530 Subject: [PATCH] feat: add missing error logs (#49) * feat: add missing error logs * fix: linting --- app.py | 3 ++- server/deployer.py | 5 ++++- server/utils.py | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 1782b93..3847dc6 100644 --- a/app.py +++ b/app.py @@ -19,6 +19,7 @@ env = os.environ.get("ENV").upper() == constants.LOCAL logging.basicConfig(level=logging.DEBUG if env else logging.INFO) +logger = logging.getLogger(__name__) async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security)): @@ -27,7 +28,7 @@ async def verify_token(credentials: HTTPAuthorizationCredentials = Depends(secur data = jwt.decode(token, app.config["SECRET_TEXT"], algorithms=["HS256"]) logging.debug(f"Authenticated successfully {data}") except Exception as e: - logging.info(f"Error while authenticating {e}") + logging.error(f"Error while authenticating {e}") raise HTTPException(status_code=401, detail="Invalid token") return data diff --git a/server/deployer.py b/server/deployer.py index 1d6ee02..d6a45ab 100644 --- a/server/deployer.py +++ b/server/deployer.py @@ -86,7 +86,10 @@ def _setup_project(self): def _configure_outer_proxy(self): if not self._project_nginx_port: - raise Exception("Project Proxy not deployed, project_nginx_port is None") + logger.error("Project Proxy not deployed, project_nginx_port is None") + raise HTTPException( + "Project Proxy not deployed, project_nginx_port is None" + ) self._nginx_helper.generate_outer_proxy_conf_file(self._project_nginx_port) self._nginx_helper.reload_nginx() diff --git a/server/utils.py b/server/utils.py index c946efb..c858c51 100644 --- a/server/utils.py +++ b/server/utils.py @@ -41,6 +41,9 @@ def __post_init__(self): self.branch_name[:20] if len(self.branch_name) > 20 else self.branch_name ) if self.branch_name == constants.DEFAULT_SECRETS_PATH: + logger.error( + f"{constants.DEFAULT_SECRETS_PATH} is a reserved keyword in Sarthi. Please use a different branch name", + ) raise HTTPException( 400, f"{constants.DEFAULT_SECRETS_PATH} is a reserved keyword in Sarthi. Please use a different branch name", @@ -268,6 +271,7 @@ def find_free_port(self) -> str: self._port = current_port return str(current_port) + logger.error("Could not find a free port in the specified range") raise HTTPException(500, "Could not find a free port in the specified range") def generate_outer_proxy_conf_file(self, port: str) -> str: @@ -284,6 +288,7 @@ def generate_outer_proxy_conf_file(self, port: str) -> str: if not self._test_nginx_config(): os.remove(self._outer_proxy_path) + logger.error("Failed creating outer_proxy_conf_file. Check with admin") raise HTTPException( 500, "Failed creating outer_proxy_conf_file. Check with admin" ) @@ -363,6 +368,7 @@ def __init__(self, project_name, branch_name, project_path): vault_url = os.environ.get("VAULT_BASE_URL") vault_token = os.environ.get("VAULT_TOKEN") if not vault_url or not vault_token: + logger.error("Vault is down or not configured correctly.") raise HTTPException(500, "Vault is down or not configured correctly.") self._project_path = project_path self._secrets_namespace = f"{project_name}/{branch_name}"