title: Nancy.Owin Error Passthrough to Owin AppBuilder pipeline?
body: <p>I have a NancyFx.OWIN application. I'm trying to leverage Katana's diagnostic "ErrorPage" (from <a href="http://www.nuget.org/packages/Microsoft.Owin.Diagnostics/2.0.0" rel="nofollow">http://www.nuget.org/packages/Microsoft.Owin.Diagnostics/2.0.0</a>) to display error Responses returned from my NancyModules.</p>
  
  <p>(Screen shots of katana error page here: <a href="http://miso-soup3.hateblo.jp/entry/2013/10/30/205653" rel="nofollow">http://miso-soup3.hateblo.jp/entry/2013/10/30/205653</a>)</p>
  
  <p>Though I can display errors from the IAppBuilder context to this page, unfortunately I can't get error responses from Nancy displayed to it.</p>
  
  <p>My Owin startup looks like this:</p>
  
  <pre><code>public class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          app.UseWelcomePage("/hello");
          NancyOptions nancyOptions = new NancyOptions();
          app.UseNancy(options =&gt; 
              options.PassThroughWhenStatusCodesAre(HttpStatusCode.InternalServerError))
              .UseErrorPage();  
      }
  }
  </code></pre>
  
  <p>this functions as this:
  1. "/hello" displays the Microsoft.Owin.Diagnostics blue smiley welcome page
  2. The routes defined in my NancyModules function as expected
  3. HttpStatusCodes != InternalServerError are handled by Nancy (displaying 'green monster' views)</p>
  
  <p>However when InternalServerError status codes are returned the OWIN IAppBuilder pipeline ignores them. So when I hit the following Nancy route:</p>
  
  <pre><code>Get["/error"] = _ =&gt;
      {
          throw new Exception("error!");
      };
  </code></pre>
  
  <p>I would expect the error to be formatted and presented ala the 'UseErrorPage()' functionality owing to my following Nancy exception pipeline which formats all exceptions into responses of InternalServerError :</p>
  
  <pre><code>public class ErrorPipeline : IApplicationStartup
  {
      public void Initialize(IPipelines pipelines)
      {
          pipelines.OnError += (context, exception) =&gt;
          {
  
              if (exception is Exception)
                  return new Response
                  {
                      StatusCode = HttpStatusCode.InternalServerError,
                      ContentType = "text/html",
                      Contents = (stream) =&gt;
                      {
                          var errorMessage =
                              Encoding.UTF8.GetBytes(
                                  exception.Message);
                          stream.Write(errorMessage, 0,
                                       errorMessage.Length);
                      }
                  };
  
              return HttpStatusCode.InternalServerError;
          };
      }
  }
  </code></pre>
  
  <p>However nothing is displayed at all. I know the pipeline error response is being sent back as a response and Nancy is passing it through, but somehow the UseErrorPage() isn't picking it up... When I remove the passthrough, "Error!" is displayed as text in the browser. <strong>Any ideas how to hook NancyFx's error responses into Owin.IAppBuilder pipeline?</strong></p>