Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit fc01619

Browse files
Ihar YakimushIhar Yakimush
authored andcommitted
rename next policy method and update readme
1 parent 01c0285 commit fc01619

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

Commmunity.AspNetCore.ExceptionHandling.Integration/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
3131

3232
services.AddExceptionHandlingPolicies(options =>
3333
{
34-
options.For<DuplicateNameException>().Retry().NextChain();
34+
options.For<DuplicateNameException>().Retry().NextPolicy();
3535

3636
options.For<DuplicateWaitObjectException>().Retry();
3737

@@ -41,7 +41,7 @@ public void ConfigureServices(IServiceCollection services)
4141
.Response(e => 400)
4242
.Headers((h, e) => h["X-qwe"] = e.Message)
4343
.WithBody((req,sw, exception) => sw.WriteAsync(exception.ToString()))
44-
.NextChain();
44+
.NextPolicy();
4545

4646
options.For<Exception>()
4747
.Log(lo => { lo.Formatter = (o, e) => "qwe"; })

Commmunity.AspNetCore.ExceptionHandling/PolicyBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static IExceptionPolicyBuilder Rethrow<TException>(
9090
/// <returns>
9191
/// Policy builder
9292
/// </returns>
93-
public static IExceptionPolicyBuilder NextChain<TException>(
93+
public static IExceptionPolicyBuilder NextPolicy<TException>(
9494
this IExceptionMapping<TException> builder, int index = -1)
9595
where TException : Exception
9696
{

Commmunity.AspNetCore.sln

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1111
ProjectSection(SolutionItems) = preProject
1212
build.ps1 = build.ps1
1313
README.md = README.md
14+
Transitions.png = Transitions.png
15+
Transitions.vsdx = Transitions.vsdx
1416
EndProjectSection
1517
EndProject
16-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commmunity.AspNetCore.ExceptionHandling.Mvc", "Commmunity.AspNetCore.ExceptionHandling.Mvc\Commmunity.AspNetCore.ExceptionHandling.Mvc.csproj", "{0D080E5A-9500-43AC-88CD-069947CFA5EF}"
18+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commmunity.AspNetCore.ExceptionHandling.Mvc", "Commmunity.AspNetCore.ExceptionHandling.Mvc\Commmunity.AspNetCore.ExceptionHandling.Mvc.csproj", "{0D080E5A-9500-43AC-88CD-069947CFA5EF}"
1719
EndProject
18-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Commmunity.AspNetCore.ExceptionHandling.NewtonsoftJson", "Commmunity.AspNetCore.ExceptionHandling.NewtonsoftJson\Commmunity.AspNetCore.ExceptionHandling.NewtonsoftJson.csproj", "{B3BAD0B5-15BC-46EE-A224-9DAF10376B81}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commmunity.AspNetCore.ExceptionHandling.NewtonsoftJson", "Commmunity.AspNetCore.ExceptionHandling.NewtonsoftJson\Commmunity.AspNetCore.ExceptionHandling.NewtonsoftJson.csproj", "{B3BAD0B5-15BC-46EE-A224-9DAF10376B81}"
1921
EndProject
2022
Global
2123
GlobalSection(SolutionConfigurationPlatforms) = preSolution

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AspNetCore-ExceptionHandling
22
Middleware to configure exception handling policies. Configure chain of handlers per exception type. OOTB handlers: log, retry, set responce headers and body
33

4-
### Sample
4+
### Code Sample
55
```
66
public void ConfigureServices(IServiceCollection services)
77
{
@@ -39,3 +39,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
3939
app.UseMvc();
4040
}
4141
```
42+
### Policy handlers transitions
43+
When exception catched in middleware it try to apply handlers from first registered policy siutable for given exception. Policy contains a chain of handlers. Each handler perform some action and apply transition. To prevent re throw of exception handlers chain MUST ends with "Handled" transition.
44+
Following handlers currently supported:
45+
46+
| Handler | Action | Transition |
47+
| ---------| ------------- | ------------- |
48+
| Rethrow | Apply ReThrow transition | ReThrow |
49+
| NextPolicy | Try to execute next policy siutable for given exception | NextPolicy |
50+
| Handled | Mark exception as handled to prevent it from bein re thrown | Handled |
51+
| Retry | Execute aspnetcore pipeline again if retry count not exceed limit | Retry (if retry limit not exceeded) or NextHandler |
52+
| Log | Log exception | NextHandler |
53+
| DisableFurtherLog | Prevent exception from being logged again in current middleware (for current request only) | NextHandler |
54+
| Response | Modify response (set status code, headers and body) depending on further response builder configuration | NextHandler |
55+
56+
![alt text](/Transitions.png)

Transitions.png

28.2 KB
Loading

Transitions.vsdx

33.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)