Spaces:
Running
Running
Delete utils/error_handling.py
Browse files- utils/error_handling.py +0 -43
utils/error_handling.py
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
#error_handling.py
|
2 |
-
import traceback
|
3 |
-
import gradio as gr
|
4 |
-
import requests
|
5 |
-
import html
|
6 |
-
|
7 |
-
def display_error(message, e=None):
|
8 |
-
"""Formats an error message for display in Gradio. Returns a gr.update object."""
|
9 |
-
error_prefix = "❌ Error: "
|
10 |
-
full_message = f"{error_prefix}{message}"
|
11 |
-
if e:
|
12 |
-
tb = traceback.format_exc()
|
13 |
-
print(f"--- ERROR ---")
|
14 |
-
print(f"Message: {message}")
|
15 |
-
print(f"Exception Type: {type(e)}")
|
16 |
-
print(f"Exception: {e}")
|
17 |
-
# Avoid printing traceback for simple Warnings like scope changes unless debugging deep
|
18 |
-
if not isinstance(e, Warning):
|
19 |
-
print(f"Traceback:\n{tb}")
|
20 |
-
print(f"-------------")
|
21 |
-
|
22 |
-
# Try to get more details from response if it's a requests error
|
23 |
-
if isinstance(e, requests.exceptions.RequestException) and e.response is not None:
|
24 |
-
try:
|
25 |
-
error_details = e.response.json()
|
26 |
-
details_str = json.dumps(error_details, indent=2)
|
27 |
-
full_message += f"\nStatus Code: {e.response.status_code}\nDetails:\n```json\n{details_str}\n```"
|
28 |
-
except json.JSONDecodeError:
|
29 |
-
full_message += f"\nStatus Code: {e.response.status_code}\nResponse Text:\n```\n{e.response.text}\n```"
|
30 |
-
elif hasattr(e, 'description'): # Handle OAuthLib errors which often have a description
|
31 |
-
full_message += f"\nDetails: {getattr(e, 'description', str(e))}"
|
32 |
-
else:
|
33 |
-
# Display the specific warning/error message directly
|
34 |
-
full_message += f"\nDetails: {str(e)}"
|
35 |
-
else:
|
36 |
-
print(f"Error: {message}") # Log simple message
|
37 |
-
|
38 |
-
# Use Markdown for better formatting in Gradio output
|
39 |
-
# Ensure it's wrapped in a way that Gradio Markdown understands as an error block if possible
|
40 |
-
# Simple red text might be best cross-platform
|
41 |
-
error_html = f"<p style='color: red; white-space: pre-wrap;'>{html.escape(full_message)}</p>"
|
42 |
-
|
43 |
-
return gr.update(value=error_html, visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|