0

I am having trouble catching error when using the Google Admin SDK and .NET. There was not much information on practical examples using this on Google's website, that I could find.

Alas, I have working code that will search a Google Apps domain for a user account and return properties about that user account. What I do not have is error handling for scenarios when the searched for user account is not found (indicating that the user does not exist).

It seems this situation is returned as an HTTP 404 response. Great. No problem in that, but I cannot seem to handle this gracefully in my app. IIS is simply throwing a "The resource could not be found" error mesage at /xxx/appname/DefaultRedirectErrorPage.aspx. I am not sure where this is coming from as it is not defined in web.config or default.asax.

If there was a practical example of how to handle such a simple response from Google, using .NET, that would be great.

Jeff
  • 1

2 Answers2

0

I dont know anything about .NET library... BUT I have worked with the underlying HTTP requests (I'm using PHP). The API may not be returning what you think it should...

If there is an error, the API should return an "error" object in the JSON response. I check for that when looking for errors.

In my interaction with the directory API, when retrieving a user that does not exist the JSON response does not contain a user object. Even with NO users returned it DOES return a 200 response, not an error.

for example, if I search for a user that does NOT exist, Google sends back something like this:

{
    "kind": "admin#directory#users",
    "etag": "\"LOTSOFCHARACTERSHERETHATAREAKEYOFSOMEKIND\""
}

when I search a valid user, the JSON I get back is like this:

{
    "kind": "admin#directory#users",
    "etag": "\"LOTSOFCHARACTERSHERETHATAREAKEYOFSOMEKIND\""
    "users": [
        "kind": "admin#directory#user",
        "id": "109020414202478541143",
        //  lots of other properties here  //
    ]
}

Are you using Google's .NET library or your own? Either way, I would check to make sure that the user object you're trying to access actually exists when an invalid user is searched.

hope that helps.

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
0

A couple years late but I was trying to figure out the same thing and found that Google doesn't have any error handling documentation around their Admin SDk. I was able to work around it with a try...catch in Google Apps Script.

try {
  var page = AdminReports.CustomerUsageReports.get(date, {
    parameters: parameters.join(','),
    maxResults: 500,
    customerId: customerId
  });
} catch (error) {
  console.log(error.code);
  console.log(error.message);
}
MattMcCode
  • 187
  • 4
  • 18