Skip to content

Commit

Permalink
refactor: ♻️ some problem detail refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Jun 15, 2023
1 parent ec58778 commit 773f0ef
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public ValueTask WriteAsync(ProblemDetailsContext context)
var mappedStatusCode = problemDetailMapper.GetMappedStatusCodes(exceptionFeature.Error);
if (mappedStatusCode > 0)
{
PopulateNewProblemDetail(context.ProblemDetails, mappedStatusCode, exceptionFeature.Error);
PopulateNewProblemDetail(
context.ProblemDetails,
context.HttpContext,
mappedStatusCode,
exceptionFeature.Error
);
context.HttpContext.Response.StatusCode = mappedStatusCode;
}
}
Expand Down Expand Up @@ -76,12 +81,14 @@ public ValueTask WriteAsync(ProblemDetailsContext context)

private static void PopulateNewProblemDetail(
ProblemDetails existingProblemDetails,
HttpContext httpContext,
int statusCode,
Exception exception
)
{
existingProblemDetails.Title = exception.GetType().Name;
existingProblemDetails.Detail = exception.Message;
existingProblemDetails.Status = statusCode;
existingProblemDetails.Instance = $"{httpContext.Request.Method} {httpContext.Request.Path}";
}
}

0 comments on commit 773f0ef

Please sign in to comment.