Skip to content

Commit ca1f983

Browse files
committed
More
1 parent 80d5b54 commit ca1f983

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/Middleware/Diagnostics/src/ExceptionHandler/ExceptionHandlerMiddlewareImpl.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,18 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
171171
context.Response.OnStarting(_clearCacheHeadersDelegate, context.Response);
172172

173173
string? handlerTag = null;
174-
var result = ExceptionHandlerResult.Unhandled;
174+
var result = ExceptionHandledType.Unhandled;
175175
foreach (var exceptionHandler in _exceptionHandlers)
176176
{
177177
if (await exceptionHandler.TryHandleAsync(context, edi.SourceException, context.RequestAborted))
178178
{
179-
result = ExceptionHandlerResult.IExceptionHandler;
179+
result = ExceptionHandledType.ExceptionHandlerService;
180180
handlerTag = exceptionHandler.GetType().FullName;
181181
break;
182182
}
183183
}
184184

185-
if (result == ExceptionHandlerResult.Unhandled)
185+
if (result == ExceptionHandledType.Unhandled)
186186
{
187187
if (_options.ExceptionHandler is not null)
188188
{
@@ -193,12 +193,12 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
193193
{
194194
if (_options.ExceptionHandlingPath.HasValue)
195195
{
196-
result = ExceptionHandlerResult.ExceptionHandlingPath;
196+
result = ExceptionHandledType.ExceptionHandlingPath;
197197
handlerTag = _options.ExceptionHandlingPath.Value;
198198
}
199199
else
200200
{
201-
result = ExceptionHandlerResult.ExceptionHandler;
201+
result = ExceptionHandledType.ExceptionHandlerCallback;
202202
}
203203
}
204204
}
@@ -212,13 +212,13 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
212212
Exception = edi.SourceException,
213213
}))
214214
{
215-
result = ExceptionHandlerResult.ProblemDetailsService;
215+
result = ExceptionHandledType.ProblemDetailsService;
216216
handlerTag = _problemDetailsService.GetType().FullName;
217217
}
218218
}
219219
}
220220

221-
if (result != ExceptionHandlerResult.Unhandled || _options.StatusCodeSelector != null || context.Response.StatusCode != StatusCodes.Status404NotFound || _options.AllowStatusCode404Response)
221+
if (result != ExceptionHandledType.Unhandled || _options.StatusCodeSelector != null || context.Response.StatusCode != StatusCodes.Status404NotFound || _options.AllowStatusCode404Response)
222222
{
223223
var suppressLogging = false;
224224

@@ -227,7 +227,12 @@ private async Task HandleException(HttpContext context, ExceptionDispatchInfo ed
227227
// Run the configured callback to determine if the exception logging in middleware should be suppressed.
228228
if (_options.SuppressLoggingCallback is { } suppressLoggingCallback)
229229
{
230-
var logContext = new ExceptionHandlerSuppressLoggingContext { Exception = edi.SourceException, HandlerResult = result };
230+
var logContext = new ExceptionHandlerSuppressLoggingContext
231+
{
232+
HttpContext = context,
233+
Exception = edi.SourceException,
234+
ExceptionHandledBy = result
235+
};
231236
suppressLogging = suppressLoggingCallback(logContext);
232237
}
233238

src/Middleware/Diagnostics/test/UnitTests/ExceptionHandlerMiddlewareTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public async Task ExceptionIsSetOnProblemDetailsContext()
8686
Assert.Equal("Test exception", originalExceptionMessage);
8787

8888
Assert.IsType<Exception>(loggingContext.Exception);
89-
Assert.Equal(ExceptionHandlerResult.ProblemDetailsService, loggingContext.HandlerResult);
89+
Assert.Equal(ExceptionHandledType.ProblemDetailsService, loggingContext.ExceptionHandledBy);
9090
}
9191

9292
[Fact]
@@ -114,9 +114,9 @@ public async Task Invoke_ExceptionThrownResultsInClearedRouteValuesAndEndpoint()
114114
}
115115

116116
[Theory]
117-
[InlineData(ExceptionHandlerResult.ExceptionHandler, false)]
118-
[InlineData(ExceptionHandlerResult.ProblemDetailsService, true)]
119-
public async Task Invoke_HasExceptionHandler_SuppressLogging_CallbackRun(ExceptionHandlerResult suppressResult, bool logged)
117+
[InlineData(ExceptionHandledType.ExceptionHandlerCallback, false)]
118+
[InlineData(ExceptionHandledType.ProblemDetailsService, true)]
119+
public async Task Invoke_HasExceptionHandler_SuppressLogging_CallbackRun(ExceptionHandledType suppressResult, bool logged)
120120
{
121121
// Arrange
122122
var sink = new TestSink();
@@ -128,7 +128,7 @@ public async Task Invoke_HasExceptionHandler_SuppressLogging_CallbackRun(Excepti
128128
context.Features.Set<IHttpResponseFeature>(new TestHttpResponseFeature());
129129
return Task.CompletedTask;
130130
},
131-
suppressLoggingCallback: c => c.HandlerResult == suppressResult);
131+
suppressLoggingCallback: c => c.ExceptionHandledBy == suppressResult);
132132
var middleware = CreateMiddleware(_ => throw new InvalidOperationException(), optionsAccessor, loggerFactory: new TestLoggerFactory(sink, true));
133133

134134
// Act & Assert

0 commit comments

Comments
 (0)