hwonder commited on
Commit
ce7112e
·
1 Parent(s): 8de00fb

Add user-friendly error messages for 401/403/500 errors

Browse files
Files changed (1) hide show
  1. src/ui/handlers.py +6 -0
src/ui/handlers.py CHANGED
@@ -19,12 +19,18 @@ def format_error(error: Exception) -> str:
19
  msg = str(error)
20
 
21
  # Translate common errors
 
 
 
 
22
  if "timeout" in msg.lower():
23
  return "The operation timed out. Please try again with a simpler prompt."
24
  if "network" in msg.lower() or "connection" in msg.lower():
25
  return "Network error. Please check your connection and try again."
26
  if "rate limit" in msg.lower() or "429" in msg.lower():
27
  return "Too many requests. Please wait a moment and try again."
 
 
28
 
29
  return f"Error: {msg}"
30
 
 
19
  msg = str(error)
20
 
21
  # Translate common errors
22
+ if "401" in msg or "unauthorized" in msg.lower():
23
+ return "Invalid API key. Please check your StackNet Key in the Settings section."
24
+ if "403" in msg or "forbidden" in msg.lower():
25
+ return "Access denied. Your API key may not have permission for this operation."
26
  if "timeout" in msg.lower():
27
  return "The operation timed out. Please try again with a simpler prompt."
28
  if "network" in msg.lower() or "connection" in msg.lower():
29
  return "Network error. Please check your connection and try again."
30
  if "rate limit" in msg.lower() or "429" in msg.lower():
31
  return "Too many requests. Please wait a moment and try again."
32
+ if "500" in msg or "internal server error" in msg.lower():
33
+ return "Server error. The service is temporarily unavailable. Please try again later."
34
 
35
  return f"Error: {msg}"
36