A class that provides custom HTML pages for HTTP errors.
Inheritance: JsonResponse
Exemplo n.º 1
0
        /// <summary>
        ///     Creates a new <see cref="T:Stumps.Web.Responses.ErrorJsonResponse" /> from an exception.
        /// </summary>
        /// <param name="ex">The exception used to generate the error.</param>
        /// <returns>A new <see cref="T:Stumps.Web.Responses.ErrorJsonResponse"/> object.</returns>
        public static ErrorJsonResponse FromException(Exception ex)
        {
            if (ex == null)
            {
                return new ErrorJsonResponse(
                    new ErrorModel
                    {
                        ErrorMessage = null,
                        Errors = null,
                        FullException = null
                    });
            }

            var rootException = ex.GetBaseException();

            var error = new ErrorModel
            {
                ErrorMessage = WebResources.ErrorUnexpected + rootException.Message,
                FullException = rootException.ToString()
            };

            ErrorJsonResponse response = null;

            try
            {
                response = new ErrorJsonResponse(error)
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
            }
            catch
            {
                if (response != null)
                {
                    response.Dispose();
                }

                throw;
            }

            return response;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates a new <see cref="T:Stumps.Web.Responses.ErrorJsonResponse" /> from an error message.
        /// </summary>
        /// <param name="message">The error message.</param>
        /// <returns>A new <see cref="T:Stumps.Web.Responses.ErrorJsonResponse"/> object.</returns>
        public static ErrorJsonResponse FromMessage(string message)
        {
            var error = new ErrorModel
            {
                ErrorMessage = message
            };

            var response = new ErrorJsonResponse(error);

            return response;
        }