Ejemplo n.º 1
0
        /// <summary>
        /// Write an error message.
        /// </summary>
        /// <param name="writer">The Xml writer to write to.</param>
        /// <param name="code">The code of the error.</param>
        /// <param name="message">The message of the error.</param>
        /// <param name="messageLanguage">The language of the message.</param>
        /// <param name="innerError">Inner error details that will be included in debug mode (if present).</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of nested inner errors to allow.</param>
        private static void WriteXmlError(XmlWriter writer, string code, string message, string messageLanguage, ODataInnerError innerError, int maxInnerErrorDepth)
        {
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(code != null, "code != null");
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageLanguage != null, "messageLanguage != null");

            // <m:error>
            writer.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataErrorElementName, AtomConstants.ODataMetadataNamespace);

            // <m:code>code</m:code>
            writer.WriteElementString(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataErrorCodeElementName, AtomConstants.ODataMetadataNamespace, code);

            // <m:message>
            writer.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataErrorMessageElementName, AtomConstants.ODataMetadataNamespace);

            // xml:lang="..."
            writer.WriteAttributeString(AtomConstants.XmlNamespacePrefix, AtomConstants.XmlLangAttributeName, AtomConstants.XmlNamespace, messageLanguage);

            writer.WriteString(message);

            // </m:message>
            writer.WriteEndElement();

            if (innerError != null)
            {
                WriteXmlInnerError(writer, innerError, AtomConstants.ODataInnerErrorElementName, /* recursionDepth */ 0, maxInnerErrorDepth);
            }

            // </m:error>
            writer.WriteEndElement();
        }
Ejemplo n.º 2
0
 private static ODataInnerError ToODataInnerError(HttpError httpError)
 {
     string innerErrorMessage = httpError.GetPropertyValue<string>(HttpErrorKeys.ExceptionMessageKey);
     if (innerErrorMessage == null)
     {
         string messageDetail = httpError.GetPropertyValue<string>(HttpErrorKeys.MessageDetailKey);
         if (messageDetail == null)
         {
             HttpError modelStateError = httpError.GetPropertyValue<HttpError>(HttpErrorKeys.ModelStateKey);
             return (modelStateError == null) ? null
                 : new ODataInnerError { Message = ConvertModelStateErrors(modelStateError) };
         }
         else
         {
             return new ODataInnerError() { Message = messageDetail };
         }
     }
     else
     {
         ODataInnerError innerError = new ODataInnerError();
         innerError.Message = innerErrorMessage;
         innerError.TypeName = httpError.GetPropertyValue<string>(HttpErrorKeys.ExceptionTypeKey);
         innerError.StackTrace = httpError.GetPropertyValue<string>(HttpErrorKeys.StackTraceKey);
         HttpError innerExceptionError = httpError.GetPropertyValue<HttpError>(HttpErrorKeys.InnerExceptionKey);
         if (innerExceptionError != null)
         {
             innerError.InnerError = ToODataInnerError(innerExceptionError);
         }
         return innerError;
     }
 }
Ejemplo n.º 3
0
        private static ODataInnerError ReadInnerErrorElement(BufferingXmlReader xmlReader, int recursionDepth, int maxInnerErrorDepth)
        {
            ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth);
            ODataInnerError error = new ODataInnerError();
            DuplicateInnerErrorElementPropertyBitMask none = DuplicateInnerErrorElementPropertyBitMask.None;
            if (xmlReader.IsEmptyElement)
            {
                goto Label_010F;
            }
            xmlReader.Read();
        Label_0022:
            switch (xmlReader.NodeType)
            {
                case XmlNodeType.Element:
                    string str;
                    if (xmlReader.NamespaceEquals(xmlReader.ODataMetadataNamespace) && ((str = xmlReader.LocalName) != null))
                    {
                        if (!(str == "message"))
                        {
                            if (str == "type")
                            {
                                VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.TypeName, "type");
                                error.TypeName = xmlReader.ReadElementValue();
                                goto Label_0102;
                            }
                            if (str == "stacktrace")
                            {
                                VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.StackTrace, "stacktrace");
                                error.StackTrace = xmlReader.ReadElementValue();
                                goto Label_0102;
                            }
                            if (str == "internalexception")
                            {
                                VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.InternalException, "internalexception");
                                error.InnerError = ReadInnerErrorElement(xmlReader, recursionDepth, maxInnerErrorDepth);
                                goto Label_0102;
                            }
                        }
                        else
                        {
                            VerifyInnerErrorElementNotFound(ref none, DuplicateInnerErrorElementPropertyBitMask.Message, "message");
                            error.Message = xmlReader.ReadElementValue();
                            goto Label_0102;
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    goto Label_0102;
            }
            xmlReader.Skip();
        Label_0102:
            if (xmlReader.NodeType != XmlNodeType.EndElement)
            {
                goto Label_0022;
            }
        Label_010F:
            xmlReader.Read();
            return error;
        }
Ejemplo n.º 4
0
 private static void WriteXmlInnerError(XmlWriter writer, ODataInnerError innerError, string innerErrorElementName, int recursionDepth, int maxInnerErrorDepth)
 {
     recursionDepth++;
     if (recursionDepth > maxInnerErrorDepth)
     {
         throw new ODataException(Strings.ValidationUtils_RecursionDepthLimitReached(maxInnerErrorDepth));
     }
     writer.WriteStartElement("m", innerErrorElementName, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     string text = innerError.Message ?? string.Empty;
     writer.WriteStartElement("message", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteString(text);
     writer.WriteEndElement();
     string str2 = innerError.TypeName ?? string.Empty;
     writer.WriteStartElement("type", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteString(str2);
     writer.WriteEndElement();
     string str3 = innerError.StackTrace ?? string.Empty;
     writer.WriteStartElement("stacktrace", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteString(str3);
     writer.WriteEndElement();
     if (innerError.InnerError != null)
     {
         WriteXmlInnerError(writer, innerError.InnerError, "internalexception", recursionDepth, maxInnerErrorDepth);
     }
     writer.WriteEndElement();
 }
Ejemplo n.º 5
0
        private static void WriteXmlInnerError(XmlWriter writer, ODataInnerError innerError, string innerErrorElementName, int recursionDepth, int maxInnerErrorDepth)
        {
            recursionDepth++;
            if (recursionDepth > maxInnerErrorDepth)
            {
                throw new ODataException(Strings.ValidationUtils_RecursionDepthLimitReached(maxInnerErrorDepth));
            }
            writer.WriteStartElement("m", innerErrorElementName, "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            string text = innerError.Message ?? string.Empty;

            writer.WriteStartElement("message", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            writer.WriteString(text);
            writer.WriteEndElement();
            string str2 = innerError.TypeName ?? string.Empty;

            writer.WriteStartElement("type", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            writer.WriteString(str2);
            writer.WriteEndElement();
            string str3 = innerError.StackTrace ?? string.Empty;

            writer.WriteStartElement("stacktrace", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
            writer.WriteString(str3);
            writer.WriteEndElement();
            if (innerError.InnerError != null)
            {
                WriteXmlInnerError(writer, innerError.InnerError, "internalexception", recursionDepth, maxInnerErrorDepth);
            }
            writer.WriteEndElement();
        }
Ejemplo n.º 6
0
        internal static void WriteXmlError(XmlWriter writer, ODataError error, bool includeDebugInformation, int maxInnerErrorDepth)
        {
            string str;
            string str2;
            string str3;

            GetErrorDetails(error, out str, out str2, out str3);
            ODataInnerError innerError = includeDebugInformation ? error.InnerError : null;

            WriteXmlError(writer, str, str2, str3, innerError, maxInnerErrorDepth);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Write an error message.
        /// </summary>
        /// <param name="writer">The Xml writer to write to.</param>
        /// <param name="error">The error instance to write.</param>
        /// <param name="includeDebugInformation">A flag indicating whether error details should be written (in debug mode only) or not.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of nested inner errors to allow.</param>
        internal static void WriteXmlError(XmlWriter writer, ODataError error, bool includeDebugInformation, int maxInnerErrorDepth)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(error != null, "error != null");

            string code, message, messageLanguage;

            ErrorUtils.GetErrorDetails(error, out code, out message, out messageLanguage);

            ODataInnerError innerError = includeDebugInformation ? error.InnerError : null;

            WriteXmlError(writer, code, message, messageLanguage, innerError, maxInnerErrorDepth);
        }
Ejemplo n.º 8
0
 private static void WriteXmlError(XmlWriter writer, string code, string message, string messageLanguage, ODataInnerError innerError, int maxInnerErrorDepth)
 {
     writer.WriteStartElement("m", "error", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteElementString("m", "code", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", code);
     writer.WriteStartElement("m", "message", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", messageLanguage);
     writer.WriteString(message);
     writer.WriteEndElement();
     if (innerError != null)
     {
         WriteXmlInnerError(writer, innerError, "innererror", 0, maxInnerErrorDepth);
     }
     writer.WriteEndElement();
 }
Ejemplo n.º 9
0
 private ODataInnerError ReadInnerError(int recursionDepth)
 {
     ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, base.MessageReaderSettings.MessageQuotas.MaxNestingDepth);
     base.JsonReader.ReadStartObject();
     ODataInnerError error = new ODataInnerError();
     ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None;
     while (base.JsonReader.NodeType == JsonNodeType.Property)
     {
         string str2 = base.JsonReader.ReadPropertyName();
         if (str2 == null)
         {
             goto Label_010E;
         }
         if (!(str2 == "message"))
         {
             if (str2 == "type")
             {
                 goto Label_00A2;
             }
             if (str2 == "stacktrace")
             {
                 goto Label_00C8;
             }
             if (str2 == "internalexception")
             {
                 goto Label_00F1;
             }
             goto Label_010E;
         }
         ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, "message");
         error.Message = base.JsonReader.ReadStringValue("message");
         continue;
     Label_00A2:
         ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.TypeName, "type");
         error.TypeName = base.JsonReader.ReadStringValue("type");
         continue;
     Label_00C8:
         ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.StackTrace, "stacktrace");
         error.StackTrace = base.JsonReader.ReadStringValue("stacktrace");
         continue;
     Label_00F1:
         ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, "internalexception");
         error.InnerError = this.ReadInnerError(recursionDepth);
         continue;
     Label_010E:
         base.JsonReader.SkipValue();
     }
     base.JsonReader.ReadEndObject();
     return error;
 }
Ejemplo n.º 10
0
 private static void WriteInnerError(JsonWriter jsonWriter, ODataInnerError innerError, string innerErrorPropertyName, int recursionDepth, int maxInnerErrorDepth)
 {
     ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, maxInnerErrorDepth);
     jsonWriter.WriteName(innerErrorPropertyName);
     jsonWriter.StartObjectScope();
     jsonWriter.WriteName("message");
     jsonWriter.WriteValue(innerError.Message ?? string.Empty);
     jsonWriter.WriteName("type");
     jsonWriter.WriteValue(innerError.TypeName ?? string.Empty);
     jsonWriter.WriteName("stacktrace");
     jsonWriter.WriteValue(innerError.StackTrace ?? string.Empty);
     if (innerError.InnerError != null)
     {
         WriteInnerError(jsonWriter, innerError.InnerError, "internalexception", recursionDepth, maxInnerErrorDepth);
     }
     jsonWriter.EndObjectScope();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Writes the inner exception information in debug mode.
        /// </summary>
        /// <param name="writer">The Xml writer to write to.</param>
        /// <param name="innerError">The inner error to write.</param>
        /// <param name="innerErrorElementName">The local name of the element representing the inner error.</param>
        /// <param name="recursionDepth">The number of times this method has been called recursively.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of nested inner errors to allow.</param>
        private static void WriteXmlInnerError(XmlWriter writer, ODataInnerError innerError, string innerErrorElementName, int recursionDepth, int maxInnerErrorDepth)
        {
            Debug.Assert(writer != null, "writer != null");

            recursionDepth++;
            if (recursionDepth > maxInnerErrorDepth)
            {
#if ODATALIB
                throw new ODataException(Strings.ValidationUtils_RecursionDepthLimitReached(maxInnerErrorDepth));
#else
                throw new ODataException(System.Data.Services.Strings.BadRequest_DeepRecursion(maxInnerErrorDepth));
#endif
            }

            // <m:innererror> or <m:internalexception>
            writer.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, innerErrorElementName, AtomConstants.ODataMetadataNamespace);

            //// NOTE: we add empty elements if no information is provided for the message, error type and stack trace
            ////       to stay compatible with Astoria.

            // <m:message>...</m:message>
            string errorMessage = innerError.Message ?? String.Empty;
            writer.WriteStartElement(AtomConstants.ODataInnerErrorMessageElementName, AtomConstants.ODataMetadataNamespace);
            writer.WriteString(errorMessage);
            writer.WriteEndElement();

            // <m:type>...</m:type>
            string errorType = innerError.TypeName ?? string.Empty;
            writer.WriteStartElement(AtomConstants.ODataInnerErrorTypeElementName, AtomConstants.ODataMetadataNamespace);
            writer.WriteString(errorType);
            writer.WriteEndElement();

            // <m:stacktrace>...</m:stacktrace>
            string errorStackTrace = innerError.StackTrace ?? String.Empty;
            writer.WriteStartElement(AtomConstants.ODataInnerErrorStackTraceElementName, AtomConstants.ODataMetadataNamespace);
            writer.WriteString(errorStackTrace);
            writer.WriteEndElement();

            if (innerError.InnerError != null)
            {
                WriteXmlInnerError(writer, innerError.InnerError, AtomConstants.ODataInnerErrorInnerErrorElementName, recursionDepth, maxInnerErrorDepth);
            }

            // </m:innererror> or </m:internalexception>
            writer.WriteEndElement();
        }
Ejemplo n.º 12
0
 private static void WriteError(JsonWriter jsonWriter, string code, string message, string messageLanguage, ODataInnerError innerError, int maxInnerErrorDepth)
 {
     jsonWriter.StartObjectScope();
     jsonWriter.WriteName("error");
     jsonWriter.StartObjectScope();
     jsonWriter.WriteName("code");
     jsonWriter.WriteValue(code);
     jsonWriter.WriteName("message");
     jsonWriter.StartObjectScope();
     jsonWriter.WriteName("lang");
     jsonWriter.WriteValue(messageLanguage);
     jsonWriter.WriteName("value");
     jsonWriter.WriteValue(message);
     jsonWriter.EndObjectScope();
     if (innerError != null)
     {
         WriteInnerError(jsonWriter, innerError, "innererror", 0, maxInnerErrorDepth);
     }
     jsonWriter.EndObjectScope();
     jsonWriter.EndObjectScope();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Writes the inner exception information in debug mode.
        /// </summary>
        /// <param name="writer">The Xml writer to write to.</param>
        /// <param name="innerError">The inner error to write.</param>
        /// <param name="innerErrorElementName">The local name of the element representing the inner error.</param>
        /// <param name="recursionDepth">The number of times this method has been called recursively.</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of nested inner errors to allow.</param>
        private static void WriteXmlInnerError(XmlWriter writer, ODataInnerError innerError, string innerErrorElementName, int recursionDepth, int maxInnerErrorDepth)
        {
            Debug.Assert(writer != null, "writer != null");

            recursionDepth++;
            if (recursionDepth > maxInnerErrorDepth)
            {
#if ODATALIB
                throw new ODataException(Strings.ValidationUtils_RecursionDepthLimitReached(maxInnerErrorDepth));
#else
                throw new ODataException(System.Data.Services.Strings.BadRequest_DeepRecursion(maxInnerErrorDepth));
#endif
            }

            // <m:innererror> or <m:internalexception>
            writer.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, innerErrorElementName, AtomConstants.ODataMetadataNamespace);

            //// NOTE: we add empty elements if no information is provided for the message, error type and stack trace
            ////       to stay compatible with Astoria.

            // <m:message>...</m:message>
            string errorMessage = innerError.Message ?? String.Empty;
            writer.WriteStartElement(AtomConstants.ODataInnerErrorMessageElementName, AtomConstants.ODataMetadataNamespace);
            writer.WriteString(errorMessage);
            writer.WriteEndElement();

            // <m:type>...</m:type>
            string errorType = innerError.TypeName ?? string.Empty;
            writer.WriteStartElement(AtomConstants.ODataInnerErrorTypeElementName, AtomConstants.ODataMetadataNamespace);
            writer.WriteString(errorType);
            writer.WriteEndElement();

            // <m:stacktrace>...</m:stacktrace>
            string errorStackTrace = innerError.StackTrace ?? String.Empty;
            writer.WriteStartElement(AtomConstants.ODataInnerErrorStackTraceElementName, AtomConstants.ODataMetadataNamespace);
            writer.WriteString(errorStackTrace);
            writer.WriteEndElement();

            if (innerError.InnerError != null)
            {
                WriteXmlInnerError(writer, innerError.InnerError, AtomConstants.ODataInnerErrorInnerErrorElementName, recursionDepth, maxInnerErrorDepth);
            }

            // </m:innererror> or </m:internalexception>
            writer.WriteEndElement();
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Write an error message.
        /// </summary>
        /// <param name="writer">The Xml writer to write to.</param>
        /// <param name="code">The code of the error.</param>
        /// <param name="message">The message of the error.</param>
        /// <param name="messageLanguage">The language of the message.</param>
        /// <param name="innerError">Inner error details that will be included in debug mode (if present).</param>
        /// <param name="maxInnerErrorDepth">The maximumum number of nested inner errors to allow.</param>
        private static void WriteXmlError(XmlWriter writer, string code, string message, string messageLanguage, ODataInnerError innerError, int maxInnerErrorDepth)
        {
            Debug.Assert(writer != null, "writer != null");
            Debug.Assert(code != null, "code != null");
            Debug.Assert(message != null, "message != null");
            Debug.Assert(messageLanguage != null, "messageLanguage != null");

            // <m:error>
            writer.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataErrorElementName, AtomConstants.ODataMetadataNamespace);

            // <m:code>code</m:code>
            writer.WriteElementString(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataErrorCodeElementName, AtomConstants.ODataMetadataNamespace, code);

            // <m:message>
            writer.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataErrorMessageElementName, AtomConstants.ODataMetadataNamespace);

            // xml:lang="..."
            writer.WriteAttributeString(AtomConstants.XmlNamespacePrefix, AtomConstants.XmlLangAttributeName, AtomConstants.XmlNamespace, messageLanguage);

            writer.WriteString(message);

            // </m:message>
            writer.WriteEndElement();

            if (innerError != null)
            {
                WriteXmlInnerError(writer, innerError, AtomConstants.ODataInnerErrorElementName, /* recursionDepth */ 0, maxInnerErrorDepth);
            }

            // </m:error>
            writer.WriteEndElement();
        }
Ejemplo n.º 15
0
 private static void WriteXmlError(XmlWriter writer, string code, string message, string messageLanguage, ODataInnerError innerError, int maxInnerErrorDepth)
 {
     writer.WriteStartElement("m", "error", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteElementString("m", "code", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata", code);
     writer.WriteStartElement("m", "message", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");
     writer.WriteAttributeString("xml", "lang", "http://www.w3.org/XML/1998/namespace", messageLanguage);
     writer.WriteString(message);
     writer.WriteEndElement();
     if (innerError != null)
     {
         WriteXmlInnerError(writer, innerError, "innererror", 0, maxInnerErrorDepth);
     }
     writer.WriteEndElement();
 }