forcedotcom / wsc

Other
269 stars 223 forks source link

ConnectionException does not show exception message when calling getMessage() #291

Open jhabarunk opened 2 years ago

jhabarunk commented 2 years ago

I am not able to get an exception message for ConnectionException when calling getMessage(). I have to use ((LoginFault) c).getExceptionMessage() to get the exception message. Please use the below screen shot for tor your reference.

public class SFConnect { private static final String AUTH_ENDPOINT = "%s/services/Soap/u/49.0"; public static void main(String[] args) throws IOException { Properties properties = new Properties(); properties.load(SFConnect.class.getClass().getResourceAsStream("/application.properties")); try { String login_url = properties.getProperty("SF_BASE_URL"); String username = properties.getProperty("USERNAME"); String pass = properties.getProperty("PASSWORD"); ConnectorConfig config = new ConnectorConfig(); config.setUsername(username); config.setPassword(pass); config.setAuthEndpoint(String.format(AUTH_ENDPOINT, login_url)); PartnerConnection connection = Connector.newConnection(config); System.out.println(connection.getConfig().getSessionId()); }catch (ConnectionException c) { System.out.println("Message: " + c.getMessage()); System.out.println("LocalizedMessage: " + c.getLocalizedMessage()); System.out.println("LoginFault: " + ((LoginFault) c).getExceptionMessage()); } } }

Output: Message: null LocalizedMessage: null LoginFault: Invalid username, password, security token; or user locked out.

v1ckm commented 1 year ago

There is an issue related to this which occurs when an UnexpectedErrorFault occurs. ConnectionException occurs with getMessage() as null. For reference, the following response is received from Salesforce:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <soapenv:Fault>
      <faultcode>sf:INVALID_OPERATION_WITH_EXPIRED_PASSWORD</faultcode>
      <faultstring>INVALID_OPERATION_WITH_EXPIRED_PASSWORD: The users password has expired, you must call SetPassword before attempting any other API operations</faultstring>
      <detail>
        <sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault">
          <sf:exceptionCode>INVALID_OPERATION_WITH_EXPIRED_PASSWORD</sf:exceptionCode>
          <sf:exceptionMessage>The users password has expired, you must call SetPassword before attempting any other API operations</sf:exceptionMessage>
        </sf:UnexpectedErrorFault>
      </detail>
    </soapenv:Fault>
  </soapenv:Body>
</soapenv:Envelope>

The following methods all return null: getMessage(), getLocalizedMessage(), getCause()

After review, it has been determined that the message is placed in the toString() method. Checking ApiFault source via force-partner-api verifies this is the case. ConnectionException.toString() will show the expected messages.

Per #82, source for force-partner-api is automatically generated. Please advise if this is the best place to open this issue or another location.

Request is to make the message available via Throwable.getMessage().