Handling a push transport error or PPG server error

On occasion, the sample app 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 BES10 or BES12.

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 app 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 applies only to a consumer app 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 app 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 applies only to a consumer app 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 app specifies an onPushTransportReady() callback in its call to the static PushService.create function so that the app 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 app handles these errors by explicitly telling the user about the errors. In your app, 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: 2015-06-11



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

comments powered by Disqus