How throw server side exceptions and handle them on the client?

Events happening in the community are now at Drupal community events on www.drupal.org.
gnugu's picture

Hi,
I'm new to Drupal, so please bare with me.

I'm creating a service mobile.whoAmI() that is to return a name of the logged in user.

The code is simple:
function mobile_service_who_am_i() {
global $user;

if (!$user->uid) {
    // User is not logged in
    return services_error(t('User is not logged in.'), 406);
} else {
    $result = new stdClass();
    $result->sessid = session_id();
    $result->user = $user->name ;

    return $result;
}

}

I have JSON-RPC server installed.

On the client I don't get any error if the user is not logged in. I tried with XML-RPC where I do get the error.
I also found this thread (http://drupal.org/node/410752) that indicates that XML-RPC was patched to take error codes into account.

My client is Android where we are discouraged to use XML-RPC.

That's why I want to use JSON-RPC, but JSON-RPC doesn't seem to create actual exception when services_error("blah", code) is used.

What is the best interface to access Drupal from mobile platform?
How can one pass exceptions from Drupal service down to the client?

Thanks.

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: