예제 #1
0
 Task <ProblemDetails> IExceptionHandler <TException> .Handle(TException exception, ExceptionHandlerContext context)
 {
     Log(exception, context);
     return(Handle(exception, context));
 }
예제 #2
0
 /// <summary>
 /// Handles an exception of <typeparamref name="TException"/>.
 /// </summary>
 /// <param name="exception">Exception to handle.</param>
 /// <param name="context">Context information.</param>
 /// <returns>A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807. </returns>
 public abstract Task <ProblemDetails> Handle(TException exception, ExceptionHandlerContext context);
예제 #3
0
 /// <summary>
 /// Logs exception through ILogger.LogError.
 /// </summary>
 /// <param name="exception">Exception to log</param>
 /// <param name="context">Context information.</param>
 protected virtual void Log(TException exception, ExceptionHandlerContext context)
 {
     Logger.LogError(exception, "{TraceId}: An unexpected error occurred.", context.TraceId);
 }
예제 #4
0
        private async Task <ProblemDetails> InvokeHandler(object exceptionHandler, Exception exception, Type exceptionType, ExceptionHandlerContext handlerContext)
        {
            try
            {
                return(await(Task <ProblemDetails>) InvokeGenericHandlerMethodInfo
                       .MakeGenericMethod(exceptionType)
                       .Invoke(null, new[] { exceptionHandler, exception, handlerContext }));
            }
            catch (Exception e)
            {
                var handlerType = exceptionHandler.GetType();
                _logger?.LogError(e, $"Handler of type {handlerType.FullName} threw an unexpected error. " +
                                  "Exception handler middleware will not handle this exception.");
            }

            return(default);