GuglielmoTor commited on
Commit
fe8ead0
·
verified ·
1 Parent(s): b905712

Update Data_Fetching_and_Rendering.py

Browse files
Files changed (1) hide show
  1. Data_Fetching_and_Rendering.py +39 -0
Data_Fetching_and_Rendering.py CHANGED
@@ -8,6 +8,45 @@ from datetime import datetime, timezone, timedelta # Added timezone, timedelta
8
  API_V2_BASE = 'https://api.linkedin.com/v2'
9
  API_REST_BASE = "https://api.linkedin.com/rest"
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def fetch_org_urn(comm_client_id, comm_token_dict):
12
  """
13
  Fetches the user's administrated organization URN and name using the Marketing token.
 
8
  API_V2_BASE = 'https://api.linkedin.com/v2'
9
  API_REST_BASE = "https://api.linkedin.com/rest"
10
 
11
+
12
+ def display_error(message, e=None):
13
+ """Formats an error message for display in Gradio. Returns a gr.update object."""
14
+ error_prefix = "❌ Error: "
15
+ full_message = f"{error_prefix}{message}"
16
+ if e:
17
+ tb = traceback.format_exc()
18
+ print(f"--- ERROR ---")
19
+ print(f"Message: {message}")
20
+ print(f"Exception Type: {type(e)}")
21
+ print(f"Exception: {e}")
22
+ # Avoid printing traceback for simple Warnings like scope changes unless debugging deep
23
+ if not isinstance(e, Warning):
24
+ print(f"Traceback:\n{tb}")
25
+ print(f"-------------")
26
+
27
+ # Try to get more details from response if it's a requests error
28
+ if isinstance(e, requests.exceptions.RequestException) and e.response is not None:
29
+ try:
30
+ error_details = e.response.json()
31
+ details_str = json.dumps(error_details, indent=2)
32
+ full_message += f"\nStatus Code: {e.response.status_code}\nDetails:\n```json\n{details_str}\n```"
33
+ except json.JSONDecodeError:
34
+ full_message += f"\nStatus Code: {e.response.status_code}\nResponse Text:\n```\n{e.response.text}\n```"
35
+ elif hasattr(e, 'description'): # Handle OAuthLib errors which often have a description
36
+ full_message += f"\nDetails: {getattr(e, 'description', str(e))}"
37
+ else:
38
+ # Display the specific warning/error message directly
39
+ full_message += f"\nDetails: {str(e)}"
40
+ else:
41
+ print(f"Error: {message}") # Log simple message
42
+
43
+ # Use Markdown for better formatting in Gradio output
44
+ # Ensure it's wrapped in a way that Gradio Markdown understands as an error block if possible
45
+ # Simple red text might be best cross-platform
46
+ error_html = f"<p style='color: red; white-space: pre-wrap;'>{html.escape(full_message)}</p>"
47
+
48
+ return gr.update(value=error_html, visible=True)
49
+
50
  def fetch_org_urn(comm_client_id, comm_token_dict):
51
  """
52
  Fetches the user's administrated organization URN and name using the Marketing token.