measmonysuon commited on
Commit
3899742
1 Parent(s): c7bb18c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -48,15 +48,32 @@ def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
48
 
49
  def request_otp(user_chat_id):
50
  try:
 
51
  response = requests.post(f"{webhook_server}/request_otp", json={"user_chat_id": user_chat_id})
52
  response.raise_for_status() # Ensure we raise an exception for HTTP errors
 
 
53
  logger.debug(f"Response status code: {response.status_code}")
54
  logger.debug(f"Response content: {response.text}")
55
- return response.json()
 
 
 
 
 
 
 
 
 
 
 
56
  except requests.RequestException as e:
 
57
  logger.error(f"Request exception: {e}")
58
- return {"success": False, "error": str(e)}
 
59
  except ValueError as e:
 
60
  logger.error(f"JSON decode error: {e}")
61
  return {"success": False, "error": "Invalid JSON response"}
62
 
 
48
 
49
  def request_otp(user_chat_id):
50
  try:
51
+ # Make the request to the /request_otp endpoint
52
  response = requests.post(f"{webhook_server}/request_otp", json={"user_chat_id": user_chat_id})
53
  response.raise_for_status() # Ensure we raise an exception for HTTP errors
54
+
55
+ # Log the response details
56
  logger.debug(f"Response status code: {response.status_code}")
57
  logger.debug(f"Response content: {response.text}")
58
+
59
+ # Parse and return the JSON response
60
+ response_data = response.json()
61
+
62
+ # Check if the response contains an error
63
+ if 'error' in response_data:
64
+ logger.error(f"Error response from /request_otp: {response_data['error']}")
65
+ return {"success": False, "error": response_data.get("error", "Unknown error")}
66
+
67
+ # Return success response
68
+ return {"success": response_data.get("success", False)}
69
+
70
  except requests.RequestException as e:
71
+ # Log request exceptions and return an error response
72
  logger.error(f"Request exception: {e}")
73
+ return {"success": False, "error": "Request exception occurred"}
74
+
75
  except ValueError as e:
76
+ # Handle JSON decode errors
77
  logger.error(f"JSON decode error: {e}")
78
  return {"success": False, "error": "Invalid JSON response"}
79