Skip to content

Instantly share code, notes, and snippets.

@brianhdk
Created March 30, 2020 13:26
Show Gist options
  • Select an option

  • Save brianhdk/4be4ea03f7453744584fc7b7e381734e to your computer and use it in GitHub Desktop.

Select an option

Save brianhdk/4be4ea03f7453744584fc7b7e381734e to your computer and use it in GitHub Desktop.
string body = await httpRequest.Read(logger);
T request;
try
{
request = JsonConvert.DeserializeObject<T>(body);
}
catch (JsonException ex)
{
logger.LogError(ex, "BadRequest with message: Error parsing body ({Message}) {Body}", ex.Message, body.MaxLengthWithDots(3000));
return new BadRequestErrorMessageResult($"Request is invalid. Error parsing body as JSON: {ex.Message}.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment