You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Jason Li <ja...@plaxo.com> on 2009/10/07 02:12:42 UTC

Returning no activities

I have 2 questions about a RESTful implementation of OpenSocial using
Shindig 1.0 in PHP.

 

1)       How do I indicate an empty set?  For example, if a request is
made for activities when a user has no activities, how should this be
handled?  I tried returning an empty array but this seems to cause an
exception.

2)       How do I indicate actual errors to Shindig?  Right now, I'm
modifying the HTTP header to indicate code 500, 400 or whatever.  Is
there a better way to do this?

 

Thanks,
Jason


Re: Returning no activities

Posted by Chris Chabot <ch...@google.com>.
Hey Jason,

On Wed, Oct 7, 2009 at 2:12 AM, Jason Li <ja...@plaxo.com> wrote:

> 1)       How do I indicate an empty set?  For example, if a request is
> made for activities when a user has no activities, how should this be
> handled?  I tried returning an empty array but this seems to cause an
> exception.
>

There are 2 possible return values, one is a RestfulCollection object, the
other is an exception, returning plain array's would make shindig upset
though since it'll try to use the RestfulCollection's methods on successful
return


> 2)       How do I indicate actual errors to Shindig?  Right now, I'm
> modifying the HTTP header to indicate code 500, 400 or whatever.  Is
> there a better way to do this?
>

Custom headers won't work if you consider that the JS API uses JSON-RPC
which can contain multiple social requests in one http post, so you would be
overwriting the http code on each request processing, and have no error
codes set in the actual result set.

As I alluded to above, errors in the social api implementation are
communicated through exceptions, shindig will catch these and depending on
if it's a REST or JSON-RPC call, do the right thing (either set http error
code, or set the error field on the json rpc response for that request key)

The supported error codes are (from src/social/service/ResponseError.php):
  /** value representing NOT IMPLEMENTED. */
  public static $NOT_IMPLEMENTED = 501;
  /** value representing UNAUTHORIZED. */
  public static $UNAUTHORIZED = 401;
  /** value representing FORBIDDEN. */
  public static $FORBIDDEN = 403;
  /** value representing BAD REQUEST. */
  public static $BAD_REQUEST = 400;
  /** value representing NOT FOUND. */
  public static $NOT_FOUND = 404;
  /** value representing content uploading exceeds the quota.*/
  public static $REQUEST_TOO_LARGE = 413;
  /** value representing INTERNAL SERVER ERROR. */
  public static $INTERNAL_ERROR = 500;
  /** value representing EXPECTATION FAILED. */
  public static $LIMIT_EXCEEDED = 409;

And you'd use them like:
throw new SocialSpiException("This is an example error message.",
ResponseError::$UNAUTHORIZED);

You can find practical examples for all of this (valid response types for
each of the functions, error types and when to use, etc) in:
http://code.google.com/p/partuza/source/browse/trunk/Shindig/PartuzaService.php
Which really is the best (/only) proper documentation we have on what is
expected unfortunately

Hope that helps !

   -- Chris