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

Commit 85bedc1

Browse files
committed
Changes type of errors on ExceptionMapper from IDictionary<string, string> to IEnumerable<KeyValuePair<string, string>> to prevent casts
1 parent eaf77eb commit 85bedc1

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/PowerUtils.AspNetCore.ErrorHandler/ErrorHandlerOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ namespace PowerUtils.AspNetCore.ErrorHandler
66
{
77
public interface IExceptionMapper
88
{
9-
(int Status, IDictionary<string, string> Errors) Handle(Exception exception);
9+
(int Status, IEnumerable<KeyValuePair<string, string>> Errors) Handle(Exception exception);
1010
}
1111

1212

1313
public class ExceptionMapper<TException> : IExceptionMapper
1414
where TException : Exception
1515
{
16-
public Func<TException, (int Status, IDictionary<string, string>)> Handler { get; set; }
16+
public Func<TException, (int Status, IEnumerable<KeyValuePair<string, string>>)> Handler { get; set; }
1717

1818

19-
public (int Status, IDictionary<string, string> Errors) Handle(Exception exception)
19+
public (int Status, IEnumerable<KeyValuePair<string, string>> Errors) Handle(Exception exception)
2020
=> Handler(exception as TException);
2121
}
2222

@@ -42,7 +42,7 @@ public ErrorHandlerOptions()
4242

4343
public static class ErrorHandlerOptionsExtensions
4444
{
45-
public static void ExceptionMapper<TException>(this ErrorHandlerOptions options, Func<TException, (int Status, IDictionary<string, string> Errors)> configureMapper)
45+
public static void ExceptionMapper<TException>(this ErrorHandlerOptions options, Func<TException, (int Status, IEnumerable<KeyValuePair<string, string>> Errors)> configureMapper)
4646
where TException : Exception
4747
{
4848
var exceptionType = typeof(TException);

src/PowerUtils.AspNetCore.ErrorHandler/ExceptionsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PowerUtils.AspNetCore.ErrorHandler
77
{
88
internal static class ExceptionsExtensions
99
{
10-
public static (int Status, IDictionary<string, string> Errors) MappingToStatusCode(this Exception exception, ErrorHandlerOptions options)
10+
public static (int Status, IEnumerable<KeyValuePair<string, string>> Errors) MappingToStatusCode(this Exception exception, ErrorHandlerOptions options)
1111
{
1212
var exceptionType = exception.GetType();
1313

src/PowerUtils.AspNetCore.ErrorHandler/Handlers/ExceptionHandlerMiddleware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ internal static IApplicationBuilder UseExceptionHandlerMiddleware(this IApplicat
4545
var options = httpContext.RequestServices.GetRequiredService<IOptions<ErrorHandlerOptions>>();
4646
var problemDetailsFactory = httpContext.RequestServices.GetRequiredService<ProblemDetailsFactory>();
4747

48-
IDictionary<string, string> errors;
48+
IEnumerable<KeyValuePair<string, string>> errors;
4949
(httpContext.Response.StatusCode, errors) = exception.MappingToStatusCode(options.Value);
5050

5151
httpContext.ResetResponse(httpContext.Response.StatusCode);

src/PowerUtils.AspNetCore.ErrorHandler/ProblemDetailsFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal static ProblemDetailsResponse Create(HttpContext httpContext)
3636
}
3737

3838

39-
internal ProblemDetailsResponse Create(HttpContext httpContext, IDictionary<string, string> errors)
39+
internal ProblemDetailsResponse Create(HttpContext httpContext, IEnumerable<KeyValuePair<string, string>> errors)
4040
{
4141
var result = Create(httpContext);
4242

0 commit comments

Comments
 (0)