Skip to content

Commit ae3dc6e

Browse files
Pd18 (dotnet#75)
* fix snip * add new snippet * add new snippet
1 parent 0abed56 commit ae3dc6e

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

fundamentals/middleware/problem-details-service/Controllers/ValuesController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public IActionResult Divide(double Numerator, double Denominator)
1515
return BadRequest();
1616
}
1717

18-
return Ok(Numerator/Denominator);
18+
return Ok(Numerator / Denominator);
1919
}
2020

2121
// /api/values2 /squareroot/4
@@ -51,7 +51,7 @@ public IActionResult Divide(double Numerator, double Denominator)
5151
return BadRequest();
5252
}
5353

54-
return Ok(Numerator/Denominator);
54+
return Ok(Numerator / Denominator);
5555
}
5656

5757
// /api/values/squareroot/4
@@ -98,7 +98,7 @@ public IActionResult Divide(double Numerator, double Denominator)
9898
);
9999
}
100100

101-
return Ok(Numerator/Denominator);
101+
return Ok(Numerator / Denominator);
102102
}
103103

104104
// /api/values3/squareroot/4
@@ -131,7 +131,7 @@ public IActionResult Squareroot(double radicand)
131131
[ApiController]
132132
public class Values4Controller : ControllerBase
133133
{
134-
// /api/values3/divide/1/2
134+
// /api/values4/divide/1/2
135135
[HttpGet("{Numerator}/{Denominator}")]
136136
public IActionResult Divide(double Numerator, double Denominator)
137137
{
@@ -142,6 +142,6 @@ public IActionResult Divide(double Numerator, double Denominator)
142142
[HttpGet("{radicand}")]
143143
public IActionResult Squareroot(double radicand)
144144
{
145-
return Ok(Math.Sqrt(radicand));
145+
return Ok(Math.Sqrt(radicand));
146146
}
147147
}

fundamentals/middleware/problem-details-service/Program.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,33 @@ await problemDetailsService.WriteAsync(new ProblemDetailsContext
279279

280280
context.Response.ContentType = Text.Plain;
281281

282+
var title = "Bad Input";
283+
var detail = "Invalid input";
284+
var type = "https://errors.example.com/badInput";
285+
282286
if (context.RequestServices.GetService<IProblemDetailsService>() is
283287
{ } problemDetailsService)
284288
{
285289
var exceptionHandlerFeature =
286290
context.Features.Get<IExceptionHandlerFeature>();
287291

288-
// Examine exceptionHandlerFeature?.Error for more details.
292+
var exceptionType = exceptionHandlerFeature?.Error;
293+
if (exceptionType != null &&
294+
exceptionType.Message.Contains("infinity"))
295+
{
296+
title = "Arguement exception";
297+
detail = "Invalid input";
298+
type = "https://errors.example.com/arguementException";
299+
}
289300

290301
await problemDetailsService.WriteAsync(new ProblemDetailsContext
291302
{
292303
HttpContext = context,
293304
ProblemDetails =
294305
{
295-
Title = "Bad Input",
296-
Detail = "Invalid input",
297-
Type = "https://tools.ietf.org/html/rfc7231#section-6.6.1"
306+
Title = title,
307+
Detail = detail,
308+
Type = type
298309
}
299310
});
300311
}

0 commit comments

Comments
 (0)