NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
859 stars 170 forks source link

Middleware registration order #137

Closed stijnherreman closed 5 years ago

stijnherreman commented 6 years ago

The documentation says:

Middleware

To add the Exceptional middleware for handling errors, add it to your Startup.Configure() method:

public void Configure(IApplicationBuilder app)
{
    app.UseExceptional();
}

It's a bit more complex than that. app.UseExceptional(); must be called after an optional app.UseDeveloperExceptionPage(); and before app.UseMvc();. Otherwise, unhandled exceptions aren't logged.

Is this a bug in the middleware, or does the documentation need to be modified?

NickCraver commented 5 years ago

Addressing a few issues individually:

  1. Exceptional has it's own .UseDeveloperExceptionPage() if you want, like this:
    services.AddExceptional(Configuration.GetSection("Exceptional"), settings =>
    {
    settings.UseExceptionalPageOnThrow = HostingEnvironment.IsDevelopment();
    });
  2. The general wrapping of anything in the ASP.NET Core middleware pipeline is "register first anything you want handled after", but I agree this isn't really widely understood and I'm more than open to improving the docs to convey this. I just took a stab at this in d12889b410628cec39603284f3a46fd7f67b7865, see what you think?
stijnherreman commented 5 years ago

Looks good. I read up on middleware in the meantime and understand it now, but the extra note will certainly be useful for others users. Thanks!

NickCraver commented 5 years ago

Closing out to cleanup - thanks!