O'Reilly logo

Programming Social Applications by Jonathan LeBlanc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling Errors Produced by the Data Pipe

When using data pipelining, you may encounter instances when the container cannot provide the information the gadget requested. Errors can result if invalid data pipe requests are being made, if the container failed to generate the data, if the current permission level granted to the application by the user is insufficient, or for any number of other possible reasons. No matter what the event that triggered the error might be, the error state should be handled within the gadget.

Let’s explore a practical example of an error case. Assume that we are trying to set up two data pipes—one to collect an external data source, and another to obtain the activities of the current viewer’s friends:

<script type="text/os-data" xmlns:os="http://ns.opensocial.org/2008/markup">
   <os:ActivitiesRequest key="viewerActivities" userid="@viewer"
                         count="20" groupId="@friends" />
   <os:HttpRequest key="dataStore" href="http://www.mysite.com/storedData.php"
                   format="json" refreshInterval="500" />
</script>

If the application does not have permission to access the activities of the viewer’s friends and our external server for the stored data is down, an error will result. There is a standard error response that should be sent within all containers to display an error message. In the case of our preceding example, a JSON object will contain both error responses (one for the standard error message and one for the down server):

{ viewerActivities: { error: {message: 'Server ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required