public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            CodeMsg codeMsg;
            var     exception = actionExecutedContext.Exception;

            if (exception is Error error)
            {
                codeMsg = error.CodeMsg;
            }
            else
            {
                codeMsg = CodeMsg.UnknownError().Msg(exception.Message);
            }
            var    method = actionExecutedContext.Request.Method.Method;
            object value;

            if (HttpMethod.GET.Equals(method))
            {
                value = codeMsg.Msg();
            }
            else
            {
                value = codeMsg.Build();
            }

            actionExecutedContext.Response =
                actionExecutedContext.Request.CreateResponse(HttpStatusCode.BadRequest, value);
        }
예제 #2
0
        public override void OnException(ExceptionContext filterContext)
        {
            base.OnException(filterContext);
            filterContext.ExceptionHandled = true;

            CodeMsg codeMsg;
            var     exception = filterContext.Exception;

            if (exception is Error error)
            {
                codeMsg = error.CodeMsg;
            }
            else
            {
                codeMsg = CodeMsg.UnknownError().Msg(exception.Message);
            }

            var method = filterContext.HttpContext.Request.HttpMethod;

            if (Constants.HttpMethod.GET.Equals(method))
            {
                filterContext.Result = codeMsg.BuildContentResult();
            }
            else
            {
                filterContext.Result = codeMsg.BuildJsonResult();
            }
        }