Skip to content

Commit f3922be

Browse files
committed
refactor: ♻️ refactor problem details exception handler
1 parent a13b01f commit f3922be

File tree

22 files changed

+190
-165
lines changed

22 files changed

+190
-165
lines changed

.config/dotnet-tools.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"rollForward": false
3232
},
3333
"dotnet-ef": {
34-
"version": "8.0.7",
34+
"version": "8.0.8",
3535
"commands": [
3636
"dotnet-ef"
3737
],

.github/release-drafter.yml

+89-76
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,49 @@ template: |
1515
$CHANGES
1616
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
1717
categories:
18-
- title: 🚀 Features
19-
labels:
20-
- feature
21-
- title: ♻️ Enhancement
22-
labels:
23-
- enhancement
24-
- refactor
25-
- title: 🐛 Bug Fixes
26-
labels:
27-
- fix
28-
- bug
29-
- title: 👷 CI
30-
labels:
31-
- ci
32-
- title: ⚠️ Breaking Changes
33-
labels:
34-
- breaking-changes
35-
- title: ⛔️ Deprecated
36-
labels:
37-
- deprecated
38-
- title: 🗑 Removed
39-
labels:
40-
- removed
41-
- title: 🔐 Security
42-
labels:
43-
- security
44-
- title: 📄 Documentation
45-
labels:
46-
- docs
47-
- documentation
48-
- title: 🧩 Dependency Updates
49-
labels:
50-
- deps
51-
- dependencies
52-
- title: 🧰 Maintenance
53-
label: 'chore'
54-
- title: 🧺 Miscellaneous #Everything except ABAP
55-
label: misc
56-
- title: 🚩 Other changes
57-
## putting no labels pr to `Other Changes` category with no label - https://github.com/release-drafter/release-drafter/issues/139#issuecomment-480473934
18+
- title: 🚀 Features
19+
labels:
20+
- feature
21+
- title: ♻️ Enhancement
22+
labels:
23+
- enhancement
24+
- refactor
25+
- title: 🐛 Bug Fixes
26+
labels:
27+
- fix
28+
- bug
29+
- title: 👷 CI
30+
labels:
31+
- ci
32+
- title: 🧪 Test
33+
labels:
34+
- test
35+
- title: ⚠️ Breaking Changes
36+
labels:
37+
- breaking-changes
38+
- title: ⛔️ Deprecated
39+
labels:
40+
- deprecated
41+
- title: 🗑 Removed
42+
labels:
43+
- removed
44+
- title: 🔐 Security
45+
labels:
46+
- security
47+
- title: 📄 Documentation
48+
labels:
49+
- docs
50+
- documentation
51+
- title: 🧩 Dependency Updates
52+
labels:
53+
- deps
54+
- dependencies
55+
- title: 🧰 Maintenance
56+
label: 'chore'
57+
- title: 🧺 Miscellaneous #Everything except ABAP
58+
label: misc
59+
- title: 🚩 Other changes
60+
## putting no labels pr to `Other Changes` category with no label - https://github.com/release-drafter/release-drafter/issues/139#issuecomment-480473934
5861

5962

6063
# https://www.trywilco.com/post/wilco-ci-cd-github-heroku
@@ -64,52 +67,62 @@ categories:
6467
# Using regex for defining rules - https://regexr.com/
6568
# https://stackoverflow.com/questions/58899999/regexp-to-match-conventional-commit-syntax
6669
autolabeler:
67-
- label: 'chore'
68-
branch:
69-
- '(chore)(\([a-z ]+\))?\/.'
70-
title:
71-
- '^(chore)(\([a-z ]+\))?: .'
72-
- label: 'bug'
73-
branch:
74-
- '(fix)(\([a-z ]+\))?\/.'
75-
title:
76-
- '^(fix)(\([a-z ]+\))?: .'
77-
- label: 'feature'
78-
branch:
79-
- '(feat)(\([a-z ]+\))?\/.'
80-
title:
81-
- '^(feat)(\([a-z ]+\))?: .'
82-
- label: 'ci/cd'
83-
branch:
84-
- '(ci)(\([a-z ]+\))?\/.'
85-
title:
86-
- '^(ci)(\([a-z ]+\))?: .'
87-
- label: 'minor'
88-
branch:
89-
- '(feat)(\([a-z ]+\))?\/.'
90-
title:
91-
- '^(feat)(\([a-z ]+\))?: .'
92-
- label: 'patch'
93-
branch:
94-
- '(fix)(\([a-z ]+\))?\/.'
95-
- '(ci)(\([a-z ]+\))?\/.'
96-
title:
97-
- '^(fix)(\([a-z ]+\))?: .'
98-
- '^(ci)(\([a-z ]+\))?: .'
70+
- label: 'chore'
71+
branch:
72+
- '(chore)(\([a-z ]+\))?\/.'
73+
title:
74+
- '^(chore)(\([a-z ]+\))?: .'
75+
- label: 'bug'
76+
branch:
77+
- '(fix)(\([a-z ]+\))?\/.'
78+
title:
79+
- '^(fix)(\([a-z ]+\))?: .'
80+
- label: 'refactor'
81+
branch:
82+
- '(refactor)(\([a-z ]+\))?\/.'
83+
title:
84+
- '^(refactor)(\([a-z ]+\))?: .'
85+
- label: 'test'
86+
branch:
87+
- '(test)(\([a-z ]+\))?\/.'
88+
title:
89+
- '^(test)(\([a-z ]+\))?: .'
90+
- label: 'feature'
91+
branch:
92+
- '(feat)(\([a-z ]+\))?\/.'
93+
title:
94+
- '^(feat)(\([a-z ]+\))?: .'
95+
- label: 'ci/cd'
96+
branch:
97+
- '(ci)(\([a-z ]+\))?\/.'
98+
title:
99+
- '^(ci)(\([a-z ]+\))?: .'
100+
- label: 'minor'
101+
branch:
102+
- '(feat)(\([a-z ]+\))?\/.'
103+
title:
104+
- '^(feat)(\([a-z ]+\))?: .'
105+
- label: 'patch'
106+
branch:
107+
- '(fix)(\([a-z ]+\))?\/.'
108+
- '(ci)(\([a-z ]+\))?\/.'
109+
title:
110+
- '^(fix)(\([a-z ]+\))?: .'
111+
- '^(ci)(\([a-z ]+\))?: .'
99112

100113
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
101114
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
102115
version-resolver:
103116
major:
104117
labels:
105-
- breaking-changes
118+
- breaking-changes
106119
minor:
107120
labels:
108-
- minor
121+
- minor
109122
patch:
110123
labels:
111-
- patch
124+
- patch
112125
default: patch
113126

114127
exclude-labels:
115-
- skip-changelog
128+
- skip-changelog

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "food-delivery-microservices",
55
"scripts": {
66
"prepare": "husky && dotnet tool restore",
7-
"install-dev-cert-bash": "curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v vs2019 -l ~/vsdbg"
7+
"install-dev-cert-bash": "curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v vs2019 -l ~/vsdbg",
8+
"upgrade-packages": "dotnet outdated food-delivery-microservices.sln"
89
},
910
"repository": {
1011
"type": "git",

src/BuildingBlocks/BuildingBlocks.Core/Exception/Types/InvalidAddressException.cs

-6
This file was deleted.

src/BuildingBlocks/BuildingBlocks.Core/Exception/Types/InvalidAmountException.cs

-6
This file was deleted.

src/BuildingBlocks/BuildingBlocks.Core/Exception/Types/InvalidCurrencyException.cs

-6
This file was deleted.

src/BuildingBlocks/BuildingBlocks.Core/Exception/Types/InvalidDateException.cs

-6
This file was deleted.

src/BuildingBlocks/BuildingBlocks.Core/Exception/Types/InvalidEmailException.cs

-6
This file was deleted.

src/BuildingBlocks/BuildingBlocks.Core/Exception/Types/InvalidPhoneNumberException.cs

-7
This file was deleted.

src/BuildingBlocks/BuildingBlocks.Core/Web/Extensions/HostEnvironmentExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace BuildingBlocks.Core.Web.Extensions;
44

55
public static class HostEnvironmentExtensions
66
{
7-
public static bool IsTest(this IHostEnvironment env) => env.IsEnvironment("Test");
7+
public static bool IsTest(this IHostEnvironment env) => env.IsEnvironment(Environments.Test);
88

9-
public static bool IsDependencyTest(this IHostEnvironment env) => env.IsEnvironment("DependencyTest");
9+
public static bool IsDependencyTest(this IHostEnvironment env) => env.IsEnvironment(Environments.DependencyTest);
1010

11-
public static bool IsDocker(this IHostEnvironment env) => env.IsEnvironment("Docker");
11+
public static bool IsDocker(this IHostEnvironment env) => env.IsEnvironment(Environments.Docker);
1212
}

src/BuildingBlocks/BuildingBlocks.HealthCheck/BuildingBlocks.HealthCheck.csproj

+6-3
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" />
3232
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" />
3333
<PackageReference Include="AspNetCore.HealthChecks.EventStore" />
34+
<PackageReference Include="prometheus-net.AspNetCore" />
35+
<PackageReference Include="prometheus-net.AspNetCore.Grpc" />
36+
<PackageReference Include="prometheus-net.AspNetCore.HealthChecks" />
3437
</ItemGroup>
3538

3639
<ItemGroup>
40+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" />
3741
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" />
38-
<PackageReference Include="prometheus-net.AspNetCore" />
39-
<PackageReference Include="prometheus-net.AspNetCore.Grpc" />
40-
<PackageReference Include="prometheus-net.AspNetCore.HealthChecks" />
42+
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.ResourceUtilization" />
43+
4144
</ItemGroup>
4245

4346
</Project>

src/BuildingBlocks/BuildingBlocks.HealthCheck/DependencyInjectionExtensions.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace BuildingBlocks.HealthCheck;
1919
// https://github.com/prometheus-net/prometheus-net
2020
public static class DependencyInjectionExtensions
2121
{
22+
private static readonly string[] _defaultTags = ["live", "ready",];
23+
2224
public static WebApplicationBuilder AddCustomHealthCheck(
2325
this WebApplicationBuilder builder,
2426
Action<IHealthChecksBuilder>? healthChecksBuilder = null,
@@ -38,10 +40,24 @@ public static WebApplicationBuilder AddCustomHealthCheck(
3840

3941
var healCheckBuilder = builder
4042
.Services.AddHealthChecks()
41-
.AddDiskStorageHealthCheck(_ => { }, tags: new[] { "live", "ready" })
42-
.AddPingHealthCheck(_ => { }, tags: new[] { "live", "ready" })
43-
.AddPrivateMemoryHealthCheck(512 * 1024 * 1024, tags: new[] { "live", "ready" })
44-
.AddDnsResolveHealthCheck(_ => { }, tags: new[] { "live", "ready" })
43+
.AddDiskStorageHealthCheck(_ => { }, tags: _defaultTags)
44+
.AddPingHealthCheck(_ => { }, tags: _defaultTags)
45+
.AddPrivateMemoryHealthCheck(512 * 1024 * 1024, tags: _defaultTags)
46+
.AddDnsResolveHealthCheck(_ => { }, tags: _defaultTags)
47+
.AddResourceUtilizationHealthCheck(o =>
48+
{
49+
o.CpuThresholds = new ResourceUsageThresholds
50+
{
51+
DegradedUtilizationPercentage = 80,
52+
UnhealthyUtilizationPercentage = 90,
53+
};
54+
o.MemoryThresholds = new ResourceUsageThresholds
55+
{
56+
DegradedUtilizationPercentage = 80,
57+
UnhealthyUtilizationPercentage = 90,
58+
};
59+
o.SamplingWindow = TimeSpan.FromSeconds(5);
60+
})
4561
.ForwardToPrometheus();
4662

4763
healthChecksBuilder?.Invoke(healCheckBuilder);

src/BuildingBlocks/BuildingBlocks.Integration.MassTransit/DependencyInjectionExtensions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using BuildingBlocks.Core.Messaging;
1010
using BuildingBlocks.Core.Reflection;
1111
using BuildingBlocks.Core.Reflection.Extensions;
12+
using BuildingBlocks.Core.Web.Extensions;
1213
using Humanizer;
1314
using MassTransit;
1415
using Microsoft.AspNetCore.Builder;
@@ -49,7 +50,7 @@ params Assembly[] scanAssemblies
4950
? scanAssemblies
5051
: ReflectionUtilities.GetReferencedAssemblies(Assembly.GetCallingAssembly()).ToArray();
5152

52-
if (!builder.Environment.IsEnvironment("test"))
53+
if (!builder.Environment.IsTest())
5354
{
5455
builder.Services.AddMassTransit(ConfiguratorAction);
5556
}

src/BuildingBlocks/BuildingBlocks.Persistence.EfCore.Postgres/DbContextDesignFactoryBase.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BuildingBlocks.Core.Persistence.EfCore;
2+
using BuildingBlocks.Core.Web;
23
using Microsoft.EntityFrameworkCore;
34
using Microsoft.EntityFrameworkCore.Design;
45
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@@ -14,7 +15,7 @@ public TDbContext CreateDbContext(string[] args)
1415
{
1516
Console.WriteLine($"BaseDirectory: {AppContext.BaseDirectory}");
1617

17-
var environmentName = env ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "test";
18+
var environmentName = env ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? Environments.Test;
1819

1920
var builder = new ConfigurationBuilder()
2021
.SetBasePath(AppContext.BaseDirectory ?? "")

src/BuildingBlocks/BuildingBlocks.Validation/Extensions/ValidatorExtensions.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ public static async Task<TRequest> HandleValidationAsync<TRequest>(
2020
{
2121
var validationResult = await validator.ValidateAsync(request, cancellationToken).ConfigureAwait(false);
2222
if (!validationResult.IsValid)
23-
throw new ValidationException(validationResult.ToValidationResultModel().Message);
23+
{
24+
throw new ValidationException(
25+
validationResult.ToValidationResultModel().Errors?.FirstOrDefault()?.Message
26+
?? validationResult.ToValidationResultModel().Message
27+
);
28+
}
2429

2530
return request;
2631
}
@@ -29,7 +34,12 @@ public static TRequest HandleValidation<TRequest>(this IValidator<TRequest> vali
2934
{
3035
var validationResult = validator.Validate(request);
3136
if (!validationResult.IsValid)
32-
throw new ValidationException(validationResult.ToValidationResultModel().Message);
37+
{
38+
throw new ValidationException(
39+
validationResult.ToValidationResultModel().Errors?.FirstOrDefault()?.Message
40+
?? validationResult.ToValidationResultModel().Message
41+
);
42+
}
3343

3444
return request;
3545
}

0 commit comments

Comments
 (0)