Looping of of js/connections/profiles when run against smartcloud



This is regarding a checkin to fix an issue that we saw on Greenhouse staging server.

There was a profiles sample in js/connections which ran in infinite loop when run against smartcloud endpoint. Though this issue will be indirectly hidden from the enduser when proper filtering would be enabled on GH so that the connections profiles samples would be hidden when smartcloud endpoint is chosen, this is a bug which we must handle in our SDK to prevent looping since end users can use an improper endpoint in their code and see this behaviour.

So the issue is the profiles sample executed the REST API "/connections/opensocial/basic/rest/people/@me/" to  fetch the details of the logged in user. This API is not supported on smartcloud and due to a bug on smartcloud server, this API always returned 401 error, which leads to authentication being kicked off repeatedly leading to a loop.

So the solution is when we get a 401, we check whether the user is authenticated and also the authentication is valid (ie the tokens havent expired) and then we break from the request and display the error message. Else we start the authentication procedure.
This logic has been implemented in endpoint.js - _isAuthRequired method and request method. Also the getErrorMessage method is changed to show a generic error message (An error has occurred) if the server doesnt return any error message. There has also been changes in isAuthenticationValid() since there was some coding error there. 

I havent replicated this logic in the deprecated xhr method in endpoint.js as I found it tricky to implement promises pattern within older pattern of callbacks.

Let me know your thoughts.

I have executed the connections/js/communities test suite on SC and Connections and checkinTestSuite and all passes.