@@ -16,23 +16,28 @@ public void ConfigureServices(IServiceCollection services)
16
16
17
17
public void Configure ( IApplicationBuilder app )
18
18
{
19
- // Configure the error handler to produces a ProblemDetails .
20
- app . UseExceptionHandler ( new ExceptionHandlerOptions
19
+ // The broken section of our application .
20
+ app . Map ( "/throw" , throwApp =>
21
21
{
22
- StatusCodeSelector = ex => ex is ConflictException
23
- ? StatusCodes . Status409Conflict
24
- : StatusCodes . Status500InternalServerError ,
22
+ // Configure the error handler to produce ProblemDetails.
23
+ throwApp . UseExceptionHandler ( ) ;
24
+ throwApp . Run ( _ => throw new Exception ( "Application Exception" ) ) ;
25
25
} ) ;
26
26
27
- // The broken section of our application.
28
- app . Map ( "/throw" , throwApp =>
27
+ app . Map ( "/throw2" , throwApp =>
29
28
{
29
+ // Configure the error handler to produce ProblemDetails with a mapped status code
30
+ throwApp . UseExceptionHandler ( new ExceptionHandlerOptions
31
+ {
32
+ StatusCodeSelector = ex => ex is ConflictException
33
+ ? StatusCodes . Status409Conflict
34
+ : StatusCodes . Status500InternalServerError ,
35
+ } ) ;
36
+
30
37
throwApp . Map ( "/conflict" , throwConflictApp =>
31
38
{
32
39
throwConflictApp . Run ( _ => throw new ConflictException ( "Conflict Exception" ) ) ;
33
40
} ) ;
34
-
35
- throwApp . Run ( _ => throw new Exception ( "Application Exception" ) ) ;
36
41
} ) ;
37
42
38
43
app . UseStaticFiles ( ) ;
@@ -43,7 +48,7 @@ public void Configure(IApplicationBuilder app)
43
48
context . Response . ContentType = "text/html" ;
44
49
await context . Response . WriteAsync ( "<html><body>Welcome to the sample<br><br>\r \n " ) ;
45
50
await context . Response . WriteAsync ( "Click here to throw an exception: <a href=\" /throw\" >throw</a><br>\r \n " ) ;
46
- await context . Response . WriteAsync ( "Click here to throw a conflict exception: <a href=\" /throw /conflict\" >throw conflict</a>\r \n " ) ;
51
+ await context . Response . WriteAsync ( "Click here to throw a conflict exception: <a href=\" /throw2 /conflict\" >throw conflict</a>\r \n " ) ;
47
52
await context . Response . WriteAsync ( "</body></html>\r \n " ) ;
48
53
} ) ;
49
54
}
0 commit comments