public TwoPhasedMiddleware(
   IPipelineMiddleware requestPipeline,
   IPipelineMiddleware responsePipeline,
   IPipelineMiddleware catastrophicFail,
   IPipelineMiddleware cleanup)
 {
   _requestPipeline = requestPipeline;
   _responsePipeline = responsePipeline;
   _catastrophicFail = catastrophicFail;
   _cleanup = cleanup;
 }
 async Task InvokeSafe(IPipelineMiddleware middleware, ICommunicationContext env)
 {
   try
   {
     await middleware.Invoke(env);
   }
   catch (Exception e)
   {
     env.ServerErrors.Add(new Error {Exception = e});
     env.Abort();
   }
 }
 public virtual IPipelineMiddleware Compose(IPipelineMiddleware next)
 {
   Next = next;
   return this;
 }