public static IHttpActionResult JsonError(this ApiController controller, string errorMessage, HttpStatusCode statusCode, Exception e = null, object tempData = null)
        {
            var result = new ErrorJsonResultModel
            {
                Status           = "error",
                Error            = errorMessage,
                ExceptionMessage = e?.Message,
                TempData         = tempData
            };

            return(ResolveDependencies(controller, (negotiator, request, formatters) => new NegotiatedContentResult <ErrorJsonResultModel>(statusCode, result, negotiator, request, formatters)));
        }
Пример #2
0
        public static ActionResult JsonError(this Controller controller, string errorMessage, HttpStatusCode statusCode, Exception e = null, object tempData = null)
        {
            var result = new ErrorJsonResultModel
            {
                Status           = "error",
                Error            = errorMessage,
                ExceptionMessage = e?.Message,
                TempData         = tempData
            };

            controller.Response.TrySkipIisCustomErrors = true;

            return(new CamelCasePropertyJsonResult
            {
                Data = result,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                StatusCode = statusCode
            });
        }