Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jhabarunk opened this issue Feb 16, 2022 · 1 comment

Comments

@jhabarunk
Copy link

jhabarunk commented Feb 16, 2022

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.

@jhabarunk jhabarunk changed the title ConnectionException does show exception message ConnectionException does not show exception message when calling getMessage() Feb 16, 2022
@v1ckm
Copy link

v1ckm commented May 31, 2023

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants