コード例 #1
0
ファイル: ErrorHandler.cs プロジェクト: nickchal/pash
 private void SerializeJsonErrorToStream(Stream stream)
 {
     JsonWriter writer = new JsonWriter(new StreamWriter(stream, this.encoding));
     try
     {
         this.SerializeJsonError(writer);
     }
     finally
     {
         writer.Flush();
     }
 }
コード例 #2
0
ファイル: ErrorHandler.cs プロジェクト: JianwenSun/cc
 /// <summary>Serializes the current exception description to the specified <paramref name="stream"/>.</summary>
 /// <param name="stream">Stream to write to.</param>
 private void SerializeJsonErrorToStream(Stream stream)
 {
     Debug.Assert(stream != null, "stream != null");
     JsonWriter jsonWriter = new JsonWriter(new StreamWriter(stream, this.encoding));
     try
     {
         SerializeJsonError(jsonWriter);
     }
     finally
     {
         // We should not close the writer, since the stream is owned by the underlying host.
         jsonWriter.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 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();
        }