public async Task Invoke(HttpContext context) { var request = new IncomingRequest(context.Request); CancellationToken cancellationToken = context.RequestAborted; try { await _messenger.Handle(request, cancellationToken).ConfigureAwait(false); } catch (Exception exception) { _logger.LogError(exception, "Unhandled exception in messenger {Messenger}.", _messenger); context.Response.StatusCode = StatusCodes.Status500InternalServerError; return; } if (request.Handled) { context.Response.StatusCode = StatusCodes.Status200OK; return; } await _next.Invoke(context).ConfigureAwait(false); }