Skip to content

Instantly share code, notes, and snippets.

@darrelmiller
Created March 31, 2014 14:39
Show Gist options
  • Save darrelmiller/9893857 to your computer and use it in GitHub Desktop.
Save darrelmiller/9893857 to your computer and use it in GitHub Desktop.
public class NullJsonHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
if (response.Content == null)
{
response.Content = new StringContent("{}");
} else if (response.Content is ObjectContent)
{
var objectContent = (ObjectContent) response.Content;
if (objectContent.Value == null)
{
response.Content = new StringContent("{}");
}
}
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment