From 7777545becc17b898eb91d9d92ad6e2fff770660 Mon Sep 17 00:00:00 2001 From: i701 Date: Thu, 17 Apr 2025 19:23:13 +0500 Subject: [PATCH] Refactor user verification to use PEOPLE_API_URL and added error handling for missing environment variable --- api/tasks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/tasks.py b/api/tasks.py index 730f999..052db95 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -4,9 +4,9 @@ import requests from apibase.env import env, BASE_DIR import os -PERSON_API_URL = env.str("PERSON_VERIFY_BASE_URL", "") env.read_env(os.path.join(BASE_DIR, ".env")) +PEOPLE_API_URL = env.str("PEOPLE_API_URL", "") def verify_user_with_person_api_task(user_id: int): @@ -17,7 +17,9 @@ def verify_user_with_person_api_task(user_id: int): user = get_object_or_404(User, id=user_id) # Call the Person API to verify the user - response = requests.get(f"{PERSON_API_URL}/api/person/{user.id_card}") + if not PEOPLE_API_URL: + raise ValueError("PEOPLE_API_URL is not set in the environment variables.") + response = requests.get(f"{PEOPLE_API_URL}/api/person/{user.id_card}") if response.status_code == 200: data = response.json() api_nic = data.get("nic")