예제 #1
0
        public override void OnException(ExceptionContext context)
        {
            if (context.Exception is AggregateException)
            {
                AggregateException aggregateException = context.Exception as AggregateException;
                foreach (Exception exception in aggregateException.InnerExceptions)
                {
                    DefaultLogger.Error(exception);
                }
                context.Exception = aggregateException.InnerException;
            }

            if (context.Exception is UnauthorizedAccessException)
            {
                context.HttpContext.Response.StatusCode = 401;
            }
            else
            {
                // Unhandled errors
#if !DEBUG
                var    errorMessage = "An unhandled error occurred.";
                string callStack    = null;
#else
                var    errorMessage = context.Exception.GetBaseException().Message;
                string callStack    = context.Exception.StackTrace;
#endif

                context.HttpContext.Response.StatusCode = 500;
            }
            // handle logging here
            JMResult result = context.HttpContext.RequestServices.GetRequiredService <IExceptionHandler>().HandleException(context.Exception);
            //always return a JSON result
            context.Result = new JsonResult(result);
            base.OnException(context);
        }
예제 #2
0
        public JMResult HandleException(Exception e)
        {
            DefaultLogger.Error(e);
            string code = "System";

            if (e is JMException)
            {
                code = (e as JMException).Code;
            }

            JMResult            result = null;
            ResultConfiguration resultConfiguration = resultConfigurationsStaticDataProvider.GetResultConfiguration(code);

            if (resultConfiguration != null)
            {
                result = new JMResult
                {
                    RedirectionInfo = new JMRedirectionInfo
                    {
                        RedirectionParameter = resultConfiguration.RedirectionParameter,
                        RedirectionType      = resultConfiguration.RedirectionType
                    },
                    Errors = new JMResultItem[]
                    {
                        new JMResultItem
                        {
                            Code    = code,
                            Message = resultConfiguration.ResultMessages.FirstOrDefault(e => e.Culture == CultureInfo.CurrentCulture.Name)?.Content
                        }
                    }
                };
            }
            else
            {
                result = new JMResult
                {
                    Errors = new JMResultItem[]
                    {
                        new JMResultItem
                        {
                            Code    = code,
                            Message = e.Message
                        }
                    }
                };
            }

            return(result);
        }
예제 #3
0
        public string Post([FromBody] RequestPayload requestMessage)
        {
            try
            {
                contextProvider.SetContext(requestMessage.Context);
                FlowConfiguration configuration = flowConfigurationProvider.GetConfiguration(requestMessage.Action);
                ValidationHelper.ExecuteValidations(configuration, requestMessage.Request);
                BaseResponse    response        = flowProvider.ExecuteFlow(serviceProvider, requestMessage.Action, requestMessage.Request);
                ResponsePayload responseMessage = new ResponsePayload
                {
                    Context  = contextProvider.GetContext(),
                    Response = response
                };

                return(responseMessage.ToJson());
            }
            catch (Exception e)
            {
                try
                {
                    JMResult result  = serviceProvider.GetRequiredService <IExceptionHandler>().HandleException(e);
                    Context  context = contextProvider.GetContext();
                    context.ActiveResult = result;
                    return(new ResponsePayload
                    {
                        Context = context,
                        Response = null
                    }.ToJson());
                }
                catch (Exception innerException)
                {
                    DefaultLogger.Error(innerException);
                    return(new ResponsePayload().ToJson());
                }
            }
        }