private async Task <IActionResult> HandleHook(HttpRequest req, ILogger log) { try { using var sr = new StreamReader(req.Body); var json = await sr.ReadToEndAsync(); log.LogDebug("Got {request}", json); var hookResponse = await _handler.HandleAsync(json); var response = new ContentResult { ContentType = "application/json; charset=utf-8", Content = JsonConvert.SerializeObject(hookResponse) }; return(response); } catch (JsonException ex) { log.LogError(ex, "handle request {function} JSON error", nameof(FulfillmentFunction)); return(new BadRequestErrorMessageResult(ex.Message)); } catch (Exception ex) { log.LogError(ex, "Error handle request {function}", nameof(FulfillmentFunction)); return(new ExceptionResult(ex, true)); } }
public async Task Post() { using (var sr = new StreamReader(Request.Body)) { var json = await sr.ReadToEndAsync(); _logger.LogDebug("Got {request}", json); var hookResponse = await _handler.HandleAsync(json); Response.ContentType = "application/json; charset=utf-8"; await Response.WriteAsync(JsonConvert.SerializeObject(hookResponse)); } }