olofd / 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

Return "error" object received from server in the Google API V3 .NET Client Exception object #480

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Target platform (e.g. Windows, Mono, Silverlight, WP7, All)?
       Google API V3 .NET Client

Feature Request:
Return the "error" object sent from the server in the Exception class object to 
allow programs using Google API V3 .NET Client to recognize and act on the 
actual error reason returned from the server rather then just generic errors 
like "Bad Request". Also makes it easier for the software developer to 
recognize the root cause of a "bug".

{
 "error": {
  "errors": [
   {
    "domain": "youtube.video",
    "reason": "invalidCategoryId",
    "message": "Bad Request",
    "locationType": "other",
    "location": "body.snippet.categoryId"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

Original issue reported on code.google.com by MikeMe...@gmail.com on 15 Jul 2014 at 6:14

GoogleCodeExporter commented 9 years ago

Original comment by pele...@google.com on 31 Jul 2014 at 2:49

GoogleCodeExporter commented 9 years ago
I am having the same problem. The following c# code produces this problem:

var youtubeService = new YouTubeService(new BaseClientService.Initializer
{
    HttpClientInitializer = new UserCredential
    (
        new GoogleAuthorizationCodeFlow
        (
            new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = new ClientSecrets
                {
                    ClientId = "ClientId",
                    ClientSecret = "ClientSecret"
                }
            }
        ),
        "user",
        new TokenResponse
        {
            RefreshToken = "RefreshToken"
        }
    ),
    ApplicationName = "ApplicationName"
});

var videoData = File.OpenRead(@"VideoPath");

var request = youtubeService.Videos.Insert(new Video
{
    Snippet = new VideoSnippet
    {
        Title = "Title",
        Description = "Description"
    },
    Status = new VideoStatus
    {
        PrivacyStatus = "PrivacyStatus"
    }
},
"snippet,status", videoData, "video/mp4");

request.ResponseReceived += results => Console.WriteLine(results);

var response = await request.UploadAsync();

Console.WriteLine(response.Exception);

The value for response.Exception is:

Value cannot be null.
Parameter name: baseUri

And the value for $exception is:

{"Response status code does not indicate success: 400 (Bad 
Request)."} System.Exception {System.Net.Http.HttpRequestException}

And Fiddler shows:

POST 
https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=sn
ippet%2Cstatus HTTP/1.1
X-Upload-Content-Type: video/mp4
X-Upload-Content-Length: 262712
User-Agent: Thuzi Video google-api-dotnet-client/1.9.0.26010 (gzip)
Authorization: Bearer ...
Content-Type: application/json; charset=utf-8
Host: www.googleapis.com
Content-Length: 79
Accept-Encoding: gzip, deflate

{"snippet":{"description":"","title":""},"status":{"privacyStatus":"unlisted"}}

HTTP/1.1 400 Bad Request
Vary: Origin
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
Content-Length: 247
Date: Mon, 18 May 2015 14:49:23 GMT
Server: UploadServer ("Built on May 8 2015 11:09:05 (1431108545)")
Alternate-Protocol: 443:quic,p=1

{
 "error": {
  "errors": [
   {
    "domain": "youtube.video",
    "reason": "invalidTitle",
    "message": "Bad Request",
    "locationType": "other",
    "location": "body.snippet.title"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

I would like to access to this error information so that I can display error 
messages that make sense.

Original comment by csc...@thuzi.com on 18 May 2015 at 3:06