Skip to content

Instantly share code, notes, and snippets.

@btodts btodts/Startup.cs
Created Apr 5, 2019

Embed
What would you like to do?
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
var exceptionHandlingFeature = context.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionHandlingFeature?.Error is GuardException ex)
{
context.Response.StatusCode = (int)HttpStatusCode.BadRequest;
context.Response.ContentType = "application/json";
await context.Response.WriteAsync($"\"{ex.ArgumentName}\": \"{ex.Message}\"");
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.