eshivakant / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

Library does not handle errors/exceptions thrown by the service #52

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Errors thrown by the service (like OutOfQuota) are not handled by the client 
library. Currently the library tries to parse the output (which contains the 
error message) like a normal response, and the Json-Deserializer will fail.

We should add some sort of exception handling to this, and we should create a 
new exception class for exceptions thrown by the service itself. Otherwise one 
has no option but to catch the generic "Exception" and assume that it is caused 
by the service.

Original issue reported on code.google.com by mlin...@google.com on 24 May 2011 at 7:41

GoogleCodeExporter commented 9 years ago
The generated code attempt to address this with

Google.Apis.Util.StandardResponse<TOutput> response = 
Newtonsoft.Json.JsonConvert.DeserializeObject 
<Google.Apis.Util.StandardResponse<TOutput>>(str);
                if ((response.Data == null)) {
                    throw new System.ApplicationException(string.Format("Failed to get response from stream, error was [{0}]", response.Error));
                }
                return response.Data;

Is this code not working or do you just want a more strongly typed exception 
thrown from this generated code?

public class ServerReturnedError extends ApplicationException ?

Original comment by davidwat...@google.com on 25 May 2011 at 7:25

GoogleCodeExporter commented 9 years ago
This exception is caught later in the code, and a different exception is thrown:

System.ApplicationException: Failed to generate object of 
type[LanguagesListResponse] from Json.

I would really recommend a strongly typed exception (basically just a 
ServiceException / GoogleServiceException) so that one can differentiate 
between exceptions thrown on purpose by the API, or unhandled exceptions thrown 
by .NET methods

Original comment by mlin...@google.com on 25 May 2011 at 2:22

GoogleCodeExporter commented 9 years ago
Good, thanks for looking into this I'm happy with that approach.

I would envision 3 exceptions with a common base

ApplicationException
   |-> GoogleApiException
           |-> Server retuned an error  - was the data passed in wrong? did this use not have permission to this object?
           |-> Failed to connect to server ( NetworkException )     - Retry once online
           |-> Other bad things  (404/5XX/ Failed to parse Json)  - FATAL

Errors which I don't know where they go
     Authentication missing/expired/no permission for this service/ developer key vs use
     Validation of message (google.api does some of the validations specified in discovery)

Original comment by davidwat...@google.com on 25 May 2011 at 3:03

GoogleCodeExporter commented 9 years ago
Fixed as part of #55

Original comment by mlin...@google.com on 8 Jun 2011 at 10:24