Skip to content

Instantly share code, notes, and snippets.

@btodts
Created April 5, 2019 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btodts/bf3708a93afeed7adf9f0196059b02b9 to your computer and use it in GitHub Desktop.
Save btodts/bf3708a93afeed7adf9f0196059b02b9 to your computer and use it in GitHub Desktop.
// 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