* fix snip

* add new snippet

* add new snippet
pull/78/head
Rick Anderson 2022-09-27 12:05:38 -10:00 committed by GitHub
parent 0abed56f1a
commit ae3dc6e0d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 9 deletions

View File

@ -131,7 +131,7 @@ public class Values3Controller : ControllerBase
[ApiController]
public class Values4Controller : ControllerBase
{
// /api/values3/divide/1/2
// /api/values4/divide/1/2
[HttpGet("{Numerator}/{Denominator}")]
public IActionResult Divide(double Numerator, double Denominator)
{

View File

@ -279,22 +279,33 @@ else
context.Response.ContentType = Text.Plain;
var title = "Bad Input";
var detail = "Invalid input";
var type = "https://errors.example.com/badInput";
if (context.RequestServices.GetService<IProblemDetailsService>() is
{ } problemDetailsService)
{
var exceptionHandlerFeature =
context.Features.Get<IExceptionHandlerFeature>();
// Examine exceptionHandlerFeature?.Error for more details.
var exceptionType = exceptionHandlerFeature?.Error;
if (exceptionType != null &&
exceptionType.Message.Contains("infinity"))
{
title = "Arguement exception";
detail = "Invalid input";
type = "https://errors.example.com/arguementException";
}
await problemDetailsService.WriteAsync(new ProblemDetailsContext
{
HttpContext = context,
ProblemDetails =
{
Title = "Bad Input",
Detail = "Invalid input",
Type = "https://tools.ietf.org/html/rfc7231#section-6.6.1"
Title = title,
Detail = detail,
Type = type
}
});
}