Handling a push transport error or PPG server error

There might be occasions when our sample application can't create or destroy a channel because of a push transport error or a PPG server error. A push transport 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. A PPG server error occurs when the PPG server is unavailable and returns an error. These errors don't occur if you're using the Push Service with the BlackBerry Enterprise Service.

When the channel operations fail because of one of these errors, the Push Service issues an error 10103 (Transport Error) or error 10110 (PPG server error). Our application displays an error message to the user when it receives one of these error codes.

void AppHeadless::onCreateChannelCompleted(const 
  bb::network::PushStatus &status, const QString &token)
{
// ...

    // Typically in your own application you wouldn't want to 
    // display this error to your users.
    QString message = tr("Create channel failed with error code: 
      %0").arg(status.code());

    Configuration config = m_configurationService.configuration();

    switch(status.code()){
    case  PushErrorCode::NoError:

	// ...
      break;
    case  PushErrorCode::TransportFailure:
      message = tr("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.");
      break;
    case PushErrorCode::SubscriptionContentNotAvailable:
      message = tr("Create channel failed as the PPG is currently 
                returning a server error. "
                "You will be notified when the PPG is available 
                again.");
      break;
    }

    sendStatusToUI(PUSH_COLLECTOR_CREATE_CHANNEL_COMPLETE, message, 
      status.code());
}

To handle these errors, our sample application connects a slot to the pushTransportReady signal so that the application can try to create or destroy the channel again. The pushTransportReady signal returns a bb::network::PushCommand object which contains the last Push Service API call that failed (either CreateChannel or DestroyChannel).

The onPushTransportReady function checks the value of bb::network::PushCommand to determine which operation failed. The function then calls either createChannel() or destroyChannel() to try to create or destroy the channel.

AppHeadless::AppHeadless()
{
// ...
 checkConnectResult(QObject::connect(m_pushNotificationService, 
   SIGNAL(pushTransportReady(bb::network::PushCommand::Type)),
   this, SLOT(onPushTransportReady(bb::network::PushCommand::Type))));
// ...
}

void AppHeadless::onPushTransportReady(bb::network::PushCommand::Type 
   command)
{
    if (command == PushCommand::CreateChannel){
        m_pushNotificationService->createChannel();
    } else {
        m_pushNotificationService->destroyChannel();
    }
}

Last modified: 2013-12-21

comments powered by Disqus