Skip to content

Commit

Permalink
MLIBZ-168 ensuring content type header is applicationjson and json pa…
Browse files Browse the repository at this point in the history
…rser lib handles array/object errors just fine
  • Loading branch information
edatkinvey committed Mar 6, 2015
1 parent 30c859f commit 6685fec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Kinvey-Xamarin/Core/AbstractKinveyClientRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ public RestResponse ExecuteUnparsed()
var req = client.ExecuteAsync(request);
var response = req.Result;

if (response.ContentType != null && !response.ContentType.ToString().Contains( "application/json")) {
throw new KinveyException ("The response contained the `Content-Type` header with value: "+ response.ContentType.ToString() + ". “application/json” expected.");
}

lastResponseCode = (int)response.StatusCode;
lastResponseMessage = response.StatusDescription;
lastResponseHeaders = new List<Parameter>();
Expand Down Expand Up @@ -300,10 +304,15 @@ public async Task<RestResponse> ExecuteUnparsedAsync()

var response = await client.ExecuteAsync(request);

if (response.ContentType != null && !response.ContentType.ToString().Contains( "application/json")) {
throw new KinveyException ("The response contained the `Content-Type` header with value: "+ response.ContentType.ToString() + ". “application/json” expected.");

}

lastResponseCode = (int)response.StatusCode;
lastResponseMessage = response.StatusDescription;
lastResponseHeaders = new List<Parameter>();

foreach (var header in response.Headers)
{
lastResponseHeaders.Add(header);
Expand Down

0 comments on commit 6685fec

Please sign in to comment.