* 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

@ -15,7 +15,7 @@ public class Values2Controller : ControllerBase
return BadRequest(); return BadRequest();
} }
return Ok(Numerator/Denominator); return Ok(Numerator / Denominator);
} }
// /api/values2 /squareroot/4 // /api/values2 /squareroot/4
@ -51,7 +51,7 @@ public class ValuesController : ControllerBase
return BadRequest(); return BadRequest();
} }
return Ok(Numerator/Denominator); return Ok(Numerator / Denominator);
} }
// /api/values/squareroot/4 // /api/values/squareroot/4
@ -98,7 +98,7 @@ public class Values3Controller : ControllerBase
); );
} }
return Ok(Numerator/Denominator); return Ok(Numerator / Denominator);
} }
// /api/values3/squareroot/4 // /api/values3/squareroot/4
@ -131,7 +131,7 @@ public class Values3Controller : ControllerBase
[ApiController] [ApiController]
public class Values4Controller : ControllerBase public class Values4Controller : ControllerBase
{ {
// /api/values3/divide/1/2 // /api/values4/divide/1/2
[HttpGet("{Numerator}/{Denominator}")] [HttpGet("{Numerator}/{Denominator}")]
public IActionResult Divide(double Numerator, double Denominator) public IActionResult Divide(double Numerator, double Denominator)
{ {
@ -142,6 +142,6 @@ public class Values4Controller : ControllerBase
[HttpGet("{radicand}")] [HttpGet("{radicand}")]
public IActionResult Squareroot(double radicand) public IActionResult Squareroot(double radicand)
{ {
return Ok(Math.Sqrt(radicand)); return Ok(Math.Sqrt(radicand));
} }
} }

View File

@ -279,22 +279,33 @@ else
context.Response.ContentType = Text.Plain; 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 if (context.RequestServices.GetService<IProblemDetailsService>() is
{ } problemDetailsService) { } problemDetailsService)
{ {
var exceptionHandlerFeature = var exceptionHandlerFeature =
context.Features.Get<IExceptionHandlerFeature>(); 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 await problemDetailsService.WriteAsync(new ProblemDetailsContext
{ {
HttpContext = context, HttpContext = context,
ProblemDetails = ProblemDetails =
{ {
Title = "Bad Input", Title = title,
Detail = "Invalid input", Detail = detail,
Type = "https://tools.ietf.org/html/rfc7231#section-6.6.1" Type = type
} }
}); });
} }