コード例 #1
0
ファイル: ErrorHandler.cs プロジェクト: nickchal/pash
 private static void SerializeJsonException(JsonWriter writer, Exception exception)
 {
     string name = "innererror";
     int num = 0;
     while (exception != null)
     {
         writer.WriteName(name);
         writer.StartObjectScope();
         num++;
         string s = exception.Message ?? string.Empty;
         writer.WriteName("message");
         writer.WriteValue(s);
         string fullName = exception.GetType().FullName;
         writer.WriteName("type");
         writer.WriteValue(fullName);
         string str4 = exception.StackTrace ?? string.Empty;
         writer.WriteName("stacktrace");
         writer.WriteValue(str4);
         exception = exception.InnerException;
         name = "internalexception";
     }
     while (num > 0)
     {
         writer.EndScope();
         num--;
     }
 }
コード例 #2
0
ファイル: ErrorHandler.cs プロジェクト: JianwenSun/cc
        /// <summary>Serializes an error in JSON format.</summary>
        /// <param name='writer'>Writer to which error should be serialized.</param>
        private void SerializeJsonError(JsonWriter writer)
        {
            Debug.Assert(writer != null, "writer != null");
            writer.StartObjectScope();  // Wrapper for error.
            writer.WriteName(XmlConstants.JsonError);

            string errorCode, message, messageLang;
            DataServiceException dataException = ExtractErrorValues(this.exceptionArgs.Exception, out errorCode, out message, out messageLang);
            writer.StartObjectScope();

            writer.WriteName(XmlConstants.JsonErrorCode);
            writer.WriteValue(errorCode);

            writer.WriteName(XmlConstants.JsonErrorMessage);
            writer.StartObjectScope();
            writer.WriteName(XmlConstants.XmlLangAttributeName);
            writer.WriteValue(messageLang);
            writer.WriteName(XmlConstants.JsonErrorValue);
            writer.WriteValue(message);
            writer.EndScope();  // </message>

            if (this.exceptionArgs.UseVerboseErrors)
            {
                Exception exception = (dataException == null) ? this.exceptionArgs.Exception : dataException.InnerException;
                SerializeJsonException(writer, exception);
            }

            writer.EndScope();  // </error>
            writer.EndScope();  // </error wrapper>
            writer.Flush();
        }
コード例 #3
0
ファイル: ErrorHandler.cs プロジェクト: nickchal/pash
 private void SerializeJsonError(JsonWriter writer)
 {
     string str;
     string str2;
     string str3;
     writer.StartObjectScope();
     writer.WriteName("error");
     DataServiceException exception = ExtractErrorValues(this.exceptionArgs.Exception, out str, out str2, out str3);
     writer.StartObjectScope();
     writer.WriteName("code");
     writer.WriteValue(str);
     writer.WriteName("message");
     writer.StartObjectScope();
     writer.WriteName("lang");
     writer.WriteValue(str3);
     writer.WriteName("value");
     writer.WriteValue(str2);
     writer.EndScope();
     if (this.exceptionArgs.UseVerboseErrors)
     {
         Exception exception2 = (exception == null) ? this.exceptionArgs.Exception : exception.InnerException;
         SerializeJsonException(writer, exception2);
     }
     writer.EndScope();
     writer.EndScope();
     writer.Flush();
 }
コード例 #4
0
ファイル: ErrorHandler.cs プロジェクト: JianwenSun/cc
        /// <summary>Serializes an exception in JSON format.</summary>
        /// <param name='writer'>Writer to which error should be serialized.</param>
        /// <param name='exception'>Exception to serialize.</param>
        private static void SerializeJsonException(JsonWriter writer, Exception exception)
        {
            string elementName = XmlConstants.JsonErrorInner;
            int nestingDepth = 0;
            while (exception != null)
            {
                writer.WriteName(elementName);
                writer.StartObjectScope();
                nestingDepth++;

                string exceptionMessage = exception.Message ?? String.Empty;
                writer.WriteName(XmlConstants.JsonErrorMessage);
                writer.WriteValue(exceptionMessage);

                string exceptionType = exception.GetType().FullName;
                writer.WriteName(XmlConstants.JsonErrorType);
                writer.WriteValue(exceptionType);

                string exceptionStackTrace = exception.StackTrace ?? String.Empty;
                writer.WriteName(XmlConstants.JsonErrorStackTrace);
                writer.WriteValue(exceptionStackTrace);

                exception = exception.InnerException;
                elementName = XmlConstants.JsonErrorInternalException;
            }

            while (nestingDepth > 0)
            {
                writer.EndScope();  // </innererror>
                nestingDepth--;
            }
        }