Vishwas1 commited on
Commit
a834015
Β·
verified Β·
1 Parent(s): b7ae0d9

Improve Salesforce connection error handling and logging

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -36,9 +36,19 @@ class SalesforceDataLoader:
36
  return f"βœ… Successfully connected to Salesforce as {username}", gr.update(visible=True), gr.update(choices=self.available_objects, value=None)
37
 
38
  except Exception as e:
39
- logger.error(f"Connection failed: {str(e)}")
 
40
  self.connected = False
41
- return f"❌ Connection failed: {str(e)}", gr.update(visible=False), gr.update(choices=[], value=None)
 
 
 
 
 
 
 
 
 
42
 
43
  def _get_available_objects(self):
44
  """Get list of available Salesforce objects"""
@@ -50,9 +60,11 @@ class SalesforceDataLoader:
50
  for obj_name in common_objects:
51
  try:
52
  # Test if object exists and is accessible
53
- getattr(self.sf, obj_name).describe()
 
54
  self.available_objects.append(obj_name)
55
- except:
 
56
  continue
57
 
58
  except Exception as e:
 
36
  return f"βœ… Successfully connected to Salesforce as {username}", gr.update(visible=True), gr.update(choices=self.available_objects, value=None)
37
 
38
  except Exception as e:
39
+ error_msg = str(e)
40
+ logger.error(f"Connection failed: {error_msg}")
41
  self.connected = False
42
+
43
+ # Provide more helpful error messages
44
+ if "INVALID_LOGIN" in error_msg:
45
+ return f"❌ Invalid credentials. Please check your username, password, and security token.", gr.update(visible=False), gr.update(choices=[], value=None)
46
+ elif "API_DISABLED_FOR_ORG" in error_msg:
47
+ return f"❌ API access is disabled for your organization. Please contact your Salesforce admin.", gr.update(visible=False), gr.update(choices=[], value=None)
48
+ elif "LOGIN_MUST_USE_SECURITY_TOKEN" in error_msg:
49
+ return f"❌ Security token required. Please append your security token to your password.", gr.update(visible=False), gr.update(choices=[], value=None)
50
+ else:
51
+ return f"❌ Connection failed: {error_msg}", gr.update(visible=False), gr.update(choices=[], value=None)
52
 
53
  def _get_available_objects(self):
54
  """Get list of available Salesforce objects"""
 
60
  for obj_name in common_objects:
61
  try:
62
  # Test if object exists and is accessible
63
+ obj = getattr(self.sf, obj_name)
64
+ obj.describe()
65
  self.available_objects.append(obj_name)
66
+ except Exception as e:
67
+ logger.debug(f"Object {obj_name} not accessible: {str(e)}")
68
  continue
69
 
70
  except Exception as e: