in src/Google.Cloud.Functions.Framework/GcfEvents/GcfConverters.cs [129:157]
private static async Task<Request> ParseRequest(HttpRequest request, ILogger logger)
{
Request parsedRequest;
if (request.ContentType != JsonContentType)
{
throw new ConversionException("Unable to convert request to CloudEvent.");
}
try
{
var json = await new StreamReader(request.Body).ReadToEndAsync();
parsedRequest = JsonSerializer.Deserialize<Request>(json) ?? throw new ConversionException("Request body parsed to null request");
}
catch (JsonException e)
{
// Note: the details of the original exception will be lost in the normal case (where it's just logged)
// but keeping in the ConversionException is useful for debugging purposes.
throw new ConversionException($"Error parsing GCF event: {e.Message}", e);
}
PubSubEventAdapter.NormalizeRawRequest(parsedRequest, request.Path.Value ?? "", logger);
parsedRequest.NormalizeContext();
if (parsedRequest.Data is null ||
string.IsNullOrEmpty(parsedRequest.Context.Id) ||
string.IsNullOrEmpty(parsedRequest.Context.Type))
{
throw new ConversionException("Event is malformed; does not contain a payload, or the event ID or type is missing.");
}
return parsedRequest;
}