/// <summary>
        /// Intercepts the specified context.
        /// </summary>
        /// <param name="exceptionContext">The context.</param>
        /// <returns></returns>
        /// <exception cref="AggregateException"></exception>
        /// <exception cref="System.AggregateException"></exception>
        public async Task InterceptAsync(IExceptionInterceptContext exceptionContext)
        {
            var handlerExecutionExceptions = new List <Exception>();

            try
            {
                foreach (var handler in _exceptionInterceptHandlers)
                {
                    try
                    {
                        await handler.HandleAsync(exceptionContext);
                    }
                    catch (Exception ex)
                    {
                        handlerExecutionExceptions.Add(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                handlerExecutionExceptions.Add(ex);
            }
            finally
            {
                if (handlerExecutionExceptions.Any())
                {
                    throw new AggregateException(handlerExecutionExceptions);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles exception asynchronously.
        /// </summary>
        /// <param name="exceptionContext">The exception context.</param>
        /// <returns></returns>
        public Task HandleAsync(IExceptionInterceptContext exceptionContext)
        {
            var     category = _exceptionCategorizer.Categorizer(exceptionContext.Exception);
            dynamic response = new ExpandoObject();

            response.Status     = category.HttpStatus;
            response.TrackingId = Guid.NewGuid().ToString();
            response.Timestamp  = DateTimeOffset.Now.ToString();
            response.Message    = category.ErrorMessage;
            response.Execution  = "Global";

            if (exceptionContext.Context.Request != null)
            {
                response.Execution = "Request";

                if (category.Category == ExceptionCategoryType.Unhandled)
                {
                    response.Developer = new ExpandoObject();
                    response.Developer.RequestMethod = exceptionContext.Context.Request.Method;
                    response.Developer.Uri           = $"{exceptionContext.Context.Request.Scheme}:{exceptionContext.Context.Request.Host}{exceptionContext.Context.Request.Path}";
                    response.Developer.ExceptionType = exceptionContext.Exception.GetType().FullName;
                    response.Developer.StackTrace    = exceptionContext.Exception.StackTrace.Trim();
                }
            }

            exceptionContext.Context.Items["exception.category"] = category;
            exceptionContext.Context.Items["exception.response"] = response;

            return(Task.FromResult(0));
        }
コード例 #3
0
        /// <summary>
        /// Handles exception asynchronously.
        /// </summary>
        /// <param name="exceptionContext">The exception context.</param>
        /// <returns></returns>
        public async Task HandleAsync(IExceptionInterceptContext exceptionContext)
        {
            var     category      = (ExceptionCategory)exceptionContext.Context.Items["exception.category"];
            dynamic response      = exceptionContext.Context.Items["exception.response"];
            dynamic finalResponse = category.DeveloperMode ? response : response.System;

            exceptionContext.Context.Response.StatusCode  = (int)category.HttpStatus;
            exceptionContext.Context.Response.ContentType = "application/json";
            await exceptionContext.Context.Response.WriteAsync((string)JsonConvert.SerializeObject(finalResponse, Formatting.Indented));
        }
コード例 #4
0
        /// <summary>
        /// Handles exception asynchronously.
        /// </summary>
        /// <param name="exceptionContext">The exception context.</param>
        /// <returns></returns>
        public Task HandleAsync(IExceptionInterceptContext exceptionContext)
        {
            var category = (ExceptionCategory)exceptionContext.Context.Items["exception.category"];

            if (category.Category == ExceptionCategoryType.Unhandled)
            {
                dynamic response = exceptionContext.Context.Items["exception.response"];

                // log whatever to the JIRA for production issue tracking
            }

            return(Task.FromResult(0));
        }
コード例 #5
0
        /// <summary>
        /// Handles exception asynchronously.
        /// </summary>
        /// <param name="exceptionContext">The exception context.</param>
        /// <returns></returns>
        public Task HandleAsync(IExceptionInterceptContext exceptionContext)
        {
            var category = (ExceptionCategory)exceptionContext.Context.Items["exception.category"];

            if (category.Category == ExceptionCategoryType.Unhandled)
            {
                dynamic response = exceptionContext.Context.Items["exception.response"];

                // log whatever to the Database
                // Note: Application Insights may be a more attractive analytical logger than rolling your own.
            }

            return(Task.FromResult(0));
        }
コード例 #6
0
 public Task HandleAsync(IExceptionInterceptContext exceptionContext)
 {
     ExceptionReceived = exceptionContext.Exception;
     return(Task.FromResult(0));
 }