Handling a push transport error or PPG server error

There might be occasions when the sample application can't create or destroy a channel because of a push transport error or a PPG server error. These errors don't occur if you're using the Push Service with the BlackBerry Enterprise Service.

Push transport error

This error occurs when there's a problem with the mobile network, the user's wireless connection, or the low-level communications layer that the Push Service uses. When the channel operations fail because of one of these problems, the Push Service issues a blackberry.push.PushService.PUSH_TRANSPORT_UNAVAILABLE error code. The sample application displays an error message to the user when it receives this error code.

else if (result == blackberry.push.PushService.PUSH_TRANSPORT_UNAVAILABLE) {
   // This error code only applies to a consumer application using the 
   // public/BIS PPG 
   document.getElementById("errormsg").innerHTML = "Error: Create 
   channel failed as the push transport " + "is unavailable. Verify 
   your mobile network and/or Wi-Fi are turned on. If they are on,  
   you will " + "be notified when the push transport is available 
   again.";
}

PPG server error

This error occurs when the PPG server is unavailable and returns an error. When the channel operations fail because of this server error, the Push Service issues a blackberry.push.PushService.PPG_SERVER_ERROR error code. The sample application displays an error message to the user when it receives this error code.

else if (result == blackberry.push.PushService.PPG_SERVER_ERROR) {
   // This error code only applies to a consumer application using the 
   // public/BIS PPG
   document.getElementById("errormsg").innerHTML = "Error: Create
   channel failed as the PPG is " + "currently returning a server  
   error. You will be notified when the PPG is available again.";                  
}

Call onPushTransportReady()

To handle the push transport error and PPG server error, the sample application specifies an onPushTransportReady() callback in its call to the static PushService.create function so that the application can try to create or destroy the channel again.

blackberry.push.PushService.create(ops, 
    sample.pushcapture.successCreatePushService,
    sample.pushcapture.failCreatePushService, 
    sample.pushcapture.onSimChange,         
    sample.pushcapture.onPushTransportReady);

The onPushTransportReady() callback checks the value of lastFailedOperation to determine which operation failed. The callback also displays a message to the user to register again if the create channel operation failed, or to unregister again if the destroy channel operation failed. The user needs to register or unregister again because the errors prevented the user from successfully registering or unregistering in the first place. For details about registering or unregistering the user, see Creating a push channel or Destroying a push channel.

sample.pushcapture.constructor.prototype.onPushTransportReady = 
   function(lastFailedOperation) {
   var message = "The push transport/wireless network/PPG is now 
       available. Please try ";

    if (lastFailedOperation == blackberry.push.PushService.
           CREATE_CHANNEL_OPERATION) {
        message += "registering ";         
    } else {
        message += "unregistering ";         
    }
       
    message += "again.";         
    
    alert(message);
}; 

The sample application handles these errors by explicitly telling the user about the errors. In your application, you could handle the errors the same way, or your onPushTransportReady callback could check which operation failed, and then try the operation again without telling the user about the errors.

Last modified: 2014-03-10



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus