protected internal virtual async Task <IServerResponseWrapper> SafeNext(IUntypedCall call, HandlingContext context, bool allowRawResponses) { log.LogTrace($"{nameof(SafeNext)}: Started. {nameof(allowRawResponses)} is [{allowRawResponses}]"); IHeaderDictionary nestedHeaders = null; try { context.OriginalHttpContext.RequestAborted.ThrowIfCancellationRequested(); var nestedHttpContext = nestedContextFactory.Create(context.OriginalHttpContext, call, context.RequestEncoding); log.LogTrace($"{nameof(SafeNext)}: invoking pipeline on nested context"); await context.Next(nestedHttpContext); nestedHeaders = nestedHttpContext.Response.Headers; var result = await responseReader.GetResponse(nestedHttpContext, call, allowRawResponses, context.OriginalHttpContext.RequestAborted); if (result == null) { throw new JsonRpcInternalException($"{nameof(ResponseReader)} returned null"); } log.LogTrace($"{nameof(SafeNext)}: Completed"); return(result); } catch (Exception e) { log.LogWarning(e, $"{nameof(SafeNext)} failed: converting exception to json response"); var response = errorFactory.ConvertExceptionToResponse(e, headerJsonRpcSerializer); return(new JsonServerResponseWrapper(response, call, nestedHeaders)); } }