/// <summary> /// Reads an inner error payload. /// </summary> /// <param name="recursionDepth">The number of times this method has been called recursively.</param> /// <returns>An <see cref="ODataInnerError"/> representing the read inner error.</returns> /// <remarks> /// Pre-Condition: any - will throw if not StartObject /// Post-Condition: JsonNodeType.Property - The next property in the error value /// JsonNodeType.EndObject - The end of the error value /// </remarks> private ODataInnerError ReadInnerError(int recursionDepth) { Debug.Assert(this.JsonReader.DisableInStreamErrorDetection, "JsonReader.DisableInStreamErrorDetection"); this.JsonReader.AssertNotBuffering(); ValidationUtils.IncreaseAndValidateRecursionDepth(ref recursionDepth, this.MessageReaderSettings.MessageQuotas.MaxNestingDepth); this.JsonReader.ReadStartObject(); ODataInnerError innerError = new ODataInnerError(); ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitField = ODataJsonReaderUtils.ErrorPropertyBitMask.None; while (this.JsonReader.NodeType == JsonNodeType.Property) { string propertyName = this.JsonReader.ReadPropertyName(); switch (propertyName) { case JsonConstants.ODataErrorInnerErrorMessageName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, JsonConstants.ODataErrorInnerErrorMessageName); innerError.Message = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorInnerErrorMessageName); break; case JsonConstants.ODataErrorInnerErrorTypeNameName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.TypeName, JsonConstants.ODataErrorInnerErrorTypeNameName); innerError.TypeName = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorInnerErrorTypeNameName); break; case JsonConstants.ODataErrorInnerErrorStackTraceName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.StackTrace, JsonConstants.ODataErrorInnerErrorStackTraceName); innerError.StackTrace = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorInnerErrorStackTraceName); break; case JsonConstants.ODataErrorInnerErrorInnerErrorName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound( ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, JsonConstants.ODataErrorInnerErrorInnerErrorName); innerError.InnerError = this.ReadInnerError(recursionDepth); break; default: // skip any unsupported properties in the inner error this.JsonReader.SkipValue(); break; } } this.JsonReader.ReadEndObject(); this.JsonReader.AssertNotBuffering(); return(innerError); }
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); }
/// <summary> /// Read a top-level error. /// </summary> /// <returns>An <see cref="ODataError"/> representing the read error.</returns> internal ODataError ReadTopLevelError() { DebugUtils.CheckNoExternalCallers(); Debug.Assert(this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: expected JsonNodeType.None, the reader must not have been used yet."); Debug.Assert(!this.JsonReader.DisableInStreamErrorDetection, "!JsonReader.DisableInStreamErrorDetection"); this.JsonReader.AssertNotBuffering(); // prevent the buffering JSON reader from detecting in-stream errors - we read the error ourselves // to throw proper exceptions this.JsonReader.DisableInStreamErrorDetection = true; ODataError error = new ODataError(); try { // Read the start of the payload (no "d" wrapper for top-level errors) this.ReadPayloadStart(/*isReadingNestedPayload*/ false, /*expectResponseWrapper*/ false); // Read the start of the error object this.JsonReader.ReadStartObject(); ODataJsonReaderUtils.ErrorPropertyBitMask propertiesFoundBitField = ODataJsonReaderUtils.ErrorPropertyBitMask.None; while (this.JsonReader.NodeType == JsonNodeType.Property) { string propertyName = this.JsonReader.ReadPropertyName(); if (string.CompareOrdinal(JsonConstants.ODataErrorName, propertyName) != 0) { // we only allow a single 'error' property for a top-level error object throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty(propertyName)); } ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.Error, JsonConstants.ODataErrorName); this.JsonReader.ReadStartObject(); while (this.JsonReader.NodeType == JsonNodeType.Property) { propertyName = this.JsonReader.ReadPropertyName(); switch (propertyName) { case JsonConstants.ODataErrorCodeName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.Code, JsonConstants.ODataErrorCodeName); error.ErrorCode = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorCodeName); break; case JsonConstants.ODataErrorMessageName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.Message, JsonConstants.ODataErrorMessageName); this.JsonReader.ReadStartObject(); while (this.JsonReader.NodeType == JsonNodeType.Property) { propertyName = this.JsonReader.ReadPropertyName(); switch (propertyName) { case JsonConstants.ODataErrorMessageLanguageName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageLanguage, JsonConstants.ODataErrorMessageLanguageName); error.MessageLanguage = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorMessageLanguageName); break; case JsonConstants.ODataErrorMessageValueName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, JsonConstants.ODataErrorMessageValueName); error.Message = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorMessageValueName); break; default: // we only allow a 'lang' and 'value' properties in the value of the 'message' property throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorMessageValueWithInvalidProperty(propertyName)); } } this.JsonReader.ReadEndObject(); break; case JsonConstants.ODataErrorInnerErrorName: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref propertiesFoundBitField, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, JsonConstants.ODataErrorInnerErrorName); error.InnerError = this.ReadInnerError(0 /* recursionDepth */); break; default: // we only allow a 'code', 'message' and 'innererror' properties in the value of the 'error' property throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorValueWithInvalidProperty(propertyName)); } } this.JsonReader.ReadEndObject(); } // Read the end of the error object this.JsonReader.ReadEndObject(); // Read the end of the response (no "d" wrapper for top-level errors) this.ReadPayloadEnd(/*isReadingNestedPayload*/ false, /*expectResponseWrapper*/ false); } finally { this.JsonReader.DisableInStreamErrorDetection = false; } Debug.Assert(this.JsonReader.NodeType == JsonNodeType.EndOfInput, "Post-Condition: JsonNodeType.EndOfInput"); this.JsonReader.AssertNotBuffering(); return(error); }
internal ODataError ReadTopLevelError() { base.JsonReader.DisableInStreamErrorDetection = true; ODataError error = new ODataError(); try { base.ReadPayloadStart(false, false); base.JsonReader.ReadStartObject(); ODataJsonReaderUtils.ErrorPropertyBitMask none = ODataJsonReaderUtils.ErrorPropertyBitMask.None; while (base.JsonReader.NodeType == JsonNodeType.Property) { string strB = base.JsonReader.ReadPropertyName(); if (string.CompareOrdinal("error", strB) != 0) { throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty(strB)); } ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Error, "error"); base.JsonReader.ReadStartObject(); while (base.JsonReader.NodeType == JsonNodeType.Property) { strB = base.JsonReader.ReadPropertyName(); string str2 = strB; if (str2 == null) { goto Label_01B8; } if (!(str2 == "code")) { if (str2 == "message") { goto Label_00D9; } if (str2 == "innererror") { goto Label_019B; } goto Label_01B8; } ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Code, "code"); error.ErrorCode = base.JsonReader.ReadStringValue("code"); continue; Label_00D9: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.Message, "message"); base.JsonReader.ReadStartObject(); while (base.JsonReader.NodeType == JsonNodeType.Property) { strB = base.JsonReader.ReadPropertyName(); string str3 = strB; if (str3 == null) { goto Label_0171; } if (!(str3 == "lang")) { if (str3 == "value") { goto Label_014B; } goto Label_0171; } ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageLanguage, "lang"); error.MessageLanguage = base.JsonReader.ReadStringValue("lang"); continue; Label_014B: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.MessageValue, "value"); error.Message = base.JsonReader.ReadStringValue("value"); continue; Label_0171: throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorMessageValueWithInvalidProperty(strB)); } base.JsonReader.ReadEndObject(); continue; Label_019B: ODataJsonReaderUtils.VerifyErrorPropertyNotFound(ref none, ODataJsonReaderUtils.ErrorPropertyBitMask.InnerError, "innererror"); error.InnerError = this.ReadInnerError(0); continue; Label_01B8: throw new ODataException(Strings.ODataJsonErrorDeserializer_TopLevelErrorValueWithInvalidProperty(strB)); } base.JsonReader.ReadEndObject(); } base.JsonReader.ReadEndObject(); base.ReadPayloadEnd(false, false); } finally { base.JsonReader.DisableInStreamErrorDetection = false; } return(error); }