Skip to content

Commit 6233f2f

Browse files
authored
✨ 431 enhanced problem details (#443)
1 parent 996dad5 commit 6233f2f

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

docs/adr/20241118-produce-useful-sql-server-exceptions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Produce useful SQL Server exceptions
22

3-
- Status: approved
3+
- Status: accepted
44
- Deciders: Daniel Mackay
55
- Date: 2024-11-18
66
- Tags: ef-core

docs/adr/20241118-replace-automapper-with-manual-mapping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Replace AutoMapper with manual mapping
22

3-
- Status: Approved
3+
- Status: accepted
44
- Deciders: Daniel Mackay, Matt Goldman
55
- Date: 2024-11-18
66
- Tags: mappers

docs/adr/20241118-use-vogen-to-simplify-strongly-typed-ids.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Use Vogen to simplify strongly typed IDs
22

3-
- Status: approved
3+
- Status: accepted
44
- Deciders: Daniel Mackay
55
- Date: 2024-11-19
66
- Tags: ddd, vogen, strongly-typed-ids
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Http.Features;
2+
3+
namespace SSW.CleanArchitecture.WebApi.Extensions;
4+
5+
public static class CustomProblemDetailsExt
6+
{
7+
public static void AddCustomProblemDetails(this IServiceCollection services)
8+
{
9+
services.AddProblemDetails(options =>
10+
{
11+
options.CustomizeProblemDetails = context =>
12+
{
13+
context.ProblemDetails.Instance = $"{context.HttpContext.Request.Method} {context.HttpContext.Request.Path}";
14+
15+
context.ProblemDetails.Extensions.TryAdd("requestId", context.HttpContext.TraceIdentifier);
16+
17+
var activity = context.HttpContext.Features.Get<IHttpActivityFeature>()?.Activity;
18+
context.ProblemDetails.Extensions.TryAdd("traceId", activity?.Id);
19+
};
20+
});
21+
}
22+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Scalar.AspNetCore;
2+
3+
namespace SSW.CleanArchitecture.WebApi.Extensions;
4+
5+
public static class CustomScalarExt
6+
{
7+
public static void MapCustomScalarApiReference(this IEndpointRouteBuilder endpoints)
8+
{
9+
endpoints.MapScalarApiReference(options => options.WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient));
10+
}
11+
}

src/WebApi/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Scalar.AspNetCore;
21
using SSW.CleanArchitecture.Application;
32
using SSW.CleanArchitecture.Infrastructure;
43
using SSW.CleanArchitecture.WebApi;
@@ -9,7 +8,7 @@
98
var builder = WebApplication.CreateBuilder(args);
109

1110
builder.AddServiceDefaults();
12-
builder.Services.AddProblemDetails();
11+
builder.Services.AddCustomProblemDetails();
1312

1413
builder.Services.AddWebApi(builder.Configuration);
1514
builder.Services.AddApplication();
@@ -29,7 +28,7 @@
2928
}
3029

3130
app.MapOpenApi();
32-
app.MapScalarApiReference(options => options.WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient));
31+
app.MapCustomScalarApiReference();
3332
app.UseHealthChecks();
3433
app.UseHttpsRedirection();
3534
app.UseStaticFiles();

0 commit comments

Comments
 (0)