Skip to content

Commit

Permalink
Handle empty error responses in media upload/download
Browse files Browse the repository at this point in the history
Fixes issue #692.
  • Loading branch information
jskeet committed Mar 7, 2016
1 parent f646ef3 commit 8c179aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ public void Download_Error_JsonResponse()
}

[Test]
public void Download_Error_PlaintextResponse()
[TestCase("Not Found")]
[TestCase("")]
public void Download_Error_PlaintextResponse(string responseText)
{
var downloadUri = "http://www.sample.com";
var chunkSize = 100;
var responseText = "Not Found";

var handler = new MultipleChunksMessageHandler { ErrorResponse = responseText };
handler.StatusCode = HttpStatusCode.NotFound;
Expand Down
6 changes: 3 additions & 3 deletions Src/Support/GoogleApis/Apis/[Media]/MediaApiErrorHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ internal static async Task<GoogleApiException> ExceptionForResponseAsync(
string message = responseText;
try
{
parsedError = service.Serializer.Deserialize<StandardResponse<object>>(responseText).Error;
if (parsedError != null)
var parsedResponse = service.Serializer.Deserialize<StandardResponse<object>>(responseText);
if (parsedResponse != null && parsedResponse.Error != null)
{
message = parsedError.ToString();
message = parsedResponse.Error.ToString();
}
}
catch (JsonException)
Expand Down

0 comments on commit 8c179aa

Please sign in to comment.