8 Replies Latest reply on Dec 17, 2014 7:01 AM by Brendan Higgins

    Correctly handling unknown client error

    Ruben Ruben

      Hi,

       

      Following the documentation, i'm trying to get my app to correctly handle unkown_client errors when a user logs in after resetting rhoconnect or having deleted the user from the console.

       

      According to the documentation, one must perform a full database reset, and try to login again. I've managed to do this without the user noticing anything, but it seems that it will generate a new device ID. This is a problem, since the old device id will be using a rhoconnect license until someone manually removes in from the web console.

       

      Is there any way around this?

        • Re: Correctly handling unknown client error
          Kutir Mobility

          Hi Ruben,

          Have you tried

          Rhom::Rhom.database_full_reset(false,true) ?

          it will reset the db and protects the client information.

          For more information,  Please see doc at http://docs.rhomobile.com/en/2.2.0/rhodes/rhom#resetting-the-database

           

           

          Visnupriya R

          Kutir Mobility

            • Re: Correctly handling unknown client error
              Ruben Ruben

              I have tried it: it does indeed not throw client information away, but the re-login attempt fails. If this is the way to go, i'll try to make it work, but it seems to me that what you want when unkown_client error happens is to reset the client info (otherwise, it would just be re-attempting login until it eventually works)

                • Re: Correctly handling unknown client error
                  Ruben Ruben

                  Quoting Rhom API docs (Rhomobile | Rhom Ruby API):

                   

                  database_fullclient_reset_and_logout

                  Reset the Rhodes model database and logout. Equivalent to Rhom::Rhom.database_full_reset(true) followed bySyncEngine.logout.

                   

                   

                  If you receive a sync error “Unknown client” message in your sync callback, this means that the RhoConnect server no longer knows about the client and a Rhom::Rhom.database_fullclient_reset_and_logout is recommended. This error requires proper intervention in your app so you can handle the state before resetting the client. For example, your sync notification could contain the following:

                   

                   

                  if @params['error_message'].downcase == 'unknown client' puts "Received unknown client, resetting!" Rhom::Rhom.database_fullclient_reset_and_logout end
                    • Re: Correctly handling unknown client error
                      Kutir Mobility

                      Ruben,

                      For "unkown_client error", you should reset the client information in the database.

                      At that time, you can use the following code to reset db

                      "Rhom::Rhom.database_full_reset" or "Rhom::Rhom.database_fullclient_reset_and_logout".

                      For License issue, you use as shown below, Rhom::Rhom.database_full_reset(false,true) It won't reset client information, so the license won't decrease.

                       

                       

                      Visnupriya R

                      Kutir Mobility

                        • Re: Correctly handling unknown client error
                          Kutir Mobility

                          Hi Ruben

                          Did you had chance to check our response?

                           

                          Thank you.

                          Kutir Mobility

                            • Re: Correctly handling unknown client error
                              Ruben Ruben

                              Hi,

                               

                              I'm still testing, but so far it seems that what did the trick for me was (javascript):

                               

                              if (params["error_code"] == 2) {

                                  /* ...

                                   * Some logic here to prevent entering here over and over again (just in case)

                                   *  ...

                                   */

                               

                                  Rho.RhoConnectClient.stopSync();

                                  Rho.RhoConnectClient.logout();

                                  Rho.ORM.databaseFullReset();

                               

                                  /* ...

                                   *  Some logic here to recover your username and password (this still feel ugly)

                                   *  ...

                                   */

                                   Rho.RhoConnectClient.login(login, pass, function (result) {

                                      var errorCode = parseInt(result.error_code);    

                                      if (errorCode == '0') {

                                         Rho.RhoConnectClient.doSync(false, 'query=' + Rho.Application.version, false);

                                      }

                              ....

                               

                              I had tested a very similar logic and it only started working when I used Rho.ORM.databaseFullReset(true), but this seems to work so far. I'll keep this thread updated if I find any other problem

                            • Re: Correctly handling unknown client error
                              Ruben Ruben

                              Just updated my answer. I noticed that database_full_reset is not enough, a logout is needed (or database_fullclient_reset_and_logout instead), otherwise it will give a unknown_error again on sync.

                      • Re: Correctly handling unknown client error
                        Brendan Higgins

                        UGH!  Tell me about it.

                         

                        I spent weeks on this trying to come up with the work around for this.  I finally found one -- well at least it did what it was supposed to do, log the person in and remove the old device id.

                         

                        I'd post the code, but in the meantime, while working though other issues with JavaScript code, we found a RhoConnect Client bug which Zebra acknowledged and put out a fix:

                         

                        https://github.com/rhomobile/rhoconnect-client/blob/fix-v4-reset/ext/rhoconnect-client/ext/shared/sync/SyncProtocol_4.h

                         

                        <edited> Oops, I should have checked the link, it does not work any more, contact me (or Zebra) for the fix </edited>

                         

                        Once I used this code, it "broke" my code for Unknown Client.

                         

                        I reverted to the documented handling and now you can do the reset and it will work.

                         

                        I have been very frustrated with the JS code so far.

                         

                        Let me know if you want more info.