public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
        {
            var wrapped = new { error = JsonErrorMessage.FromException(error, includeExceptionDetailInFaults) };

            var statusCode = HttpStatusCode.InternalServerError;

            if (error is WebFaultException)
            {
                statusCode = ((WebFaultException)error).StatusCode;
            }

            fault = NewtonsoftJsonDispatchFormatter.FormatObjectAsMessage(wrapped, version, "fault", statusCode);
        }
        public static JsonErrorMessage FromException(Exception ex, bool includeExceptionDetailInFaults)
        {
            JsonErrorMessage result = null;

            if (includeExceptionDetailInFaults)
            {
                result = new JsonErrorMessage(ex.Message, ex.StackTrace);
                if (ex.InnerException != null)
                {
                    result.Inner = FromException(ex.InnerException, includeExceptionDetailInFaults);
                }
            }
            else
            {
                result = new JsonErrorMessage(ex.Message);
            }

            return(result);
        }