Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RequestId to failed responses without exception in Boilerplate (#10164) #10177

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ public partial class ServerExceptionHandler : SharedExceptionHandler, IProblemDe

private static readonly Guid appSessionId = Guid.NewGuid();

public bool CanWrite(ProblemDetailsContext context) => context.Exception is not null;
public bool CanWrite(ProblemDetailsContext context) => true;

public async ValueTask WriteAsync(ProblemDetailsContext context)
{
var exception = UnWrapException(context.Exception!);

var httpContext = context.HttpContext;

// Using the Request-Id header, one can find the log for server-related exceptions
httpContext.Response.Headers.Append(HeaderNames.RequestId, httpContext.TraceIdentifier);

if (context.Exception is null)
return;

var exception = UnWrapException(context.Exception);

Handle(exception, null, httpContext, out var statusCode, out var problemDetail);
httpContext.Response.StatusCode = statusCode;

Expand Down
Loading