コード例 #1
0
        private ODataErrorDetail ReadDetail()
        {
            var detail = new ODataErrorDetail();

            ReadJsonObjectInErrorPayload(
                (propertyName, duplicationPropertyNameChecker) =>
                ReadPropertyValueInODataErrorDetailObject(detail, propertyName));

            return(detail);
        }
コード例 #2
0
 private static IEnumerable <ODataErrorDetail> ToODataErrorDetails(string key, ModelStateEntry modelStateEntry)
 {
     foreach (var error in modelStateEntry.Errors)
     {
         var detail = new ODataErrorDetail();
         detail.ErrorCode = error.Exception?.Source;
         detail.Target    = key;
         detail.Message   = error.Exception?.Message ?? error.ErrorMessage;
         yield return(detail);
     }
 }
コード例 #3
0
        private void ReadPropertyValueInODataErrorDetailObject(ODataErrorDetail detail, string propertyName)
        {
            switch (propertyName)
            {
            case JsonConstants.ODataErrorCodeName:
                detail.ErrorCode = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorCodeName);
                break;

            case JsonConstants.ODataErrorMessageName:
                detail.Message = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorMessageName);
                break;

            case JsonConstants.ODataErrorTargetName:
                detail.Target = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorTargetName);
                break;

            default:
                this.JsonReader.SkipValue();
                break;
            }
        }
コード例 #4
0
        /// <summary>
        /// Asynchronously reads an error details array.
        /// </summary>
        /// <returns>A task that represents the asynchronous read operation.</returns>
        private async Task <ICollection <ODataErrorDetail> > ReadErrorDetailsAsync()
        {
            var details = new List <ODataErrorDetail>();

            // [
            await this.JsonReader.ReadStartArrayAsync()
            .ConfigureAwait(false);

            while (JsonReader.NodeType == JsonNodeType.StartObject)
            {
                var detail = new ODataErrorDetail();

                await ReadJsonObjectInErrorPayloadAsync(
                    (propertyName, duplicationPropertyNameChecker) => ReadPropertyValueInODataErrorDetailObjectAsync(detail, propertyName)).ConfigureAwait(false);

                details.Add(detail);
            }

            // ]
            await this.JsonReader.ReadEndArrayAsync()
            .ConfigureAwait(false);

            return(details);
        }
コード例 #5
0
        private void ReadPropertyValueInODataErrorDetailObject(ODataErrorDetail detail, string propertyName)
        {
            switch (propertyName)
            {
                case JsonConstants.ODataErrorCodeName:
                    detail.ErrorCode = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorCodeName);
                    break;

                case JsonConstants.ODataErrorMessageName:
                    detail.Message = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorMessageName);
                    break;

                case JsonConstants.ODataErrorTargetName:
                    detail.Target = this.JsonReader.ReadStringValue(JsonConstants.ODataErrorTargetName);
                    break;

                default:
                    this.JsonReader.SkipValue();
                    break;
            }
        }
コード例 #6
0
        private ODataErrorDetail ReadDetail()
        {
            var detail = new ODataErrorDetail();

            ReadJsonObjectInErrorPayload(
                (propertyName, duplicationPropertyNameChecker) =>
                ReadPropertyValueInODataErrorDetailObject(detail, propertyName));

            return detail;
        }
コード例 #7
0
        private bool TryReadErrorDetail(out ODataErrorDetail detail)
        {
            Debug.Assert(
                this.currentBufferedNode.NodeType == JsonNodeType.StartObject,
                "this.currentBufferedNode.NodeType == JsonNodeType.StartObject");
            Debug.Assert(this.parsingInStreamError, "this.parsingInStreamError");
            this.AssertBuffering();

            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                detail = null;
                return(false);
            }

            // {
            ReadInternal();

            detail = new ODataErrorDetail();

            // we expect one of the supported properties for the value (or end-object)
            var propertiesFoundBitmask = ODataJsonLightReaderUtils.ErrorPropertyBitMask.None;

            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                var propertyName = (string)this.currentBufferedNode.Value;

                switch (propertyName)
                {
                case JsonConstants.ODataErrorCodeName:
                    if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(
                            ref propertiesFoundBitmask,
                            ODataJsonLightReaderUtils.ErrorPropertyBitMask.Code))
                    {
                        return(false);
                    }

                    string code;
                    if (this.TryReadErrorStringPropertyValue(out code))
                    {
                        detail.ErrorCode = code;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorTargetName:
                    if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(
                            ref propertiesFoundBitmask,
                            ODataJsonLightReaderUtils.ErrorPropertyBitMask.Target))
                    {
                        return(false);
                    }

                    string target;
                    if (this.TryReadErrorStringPropertyValue(out target))
                    {
                        detail.Target = target;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                case JsonConstants.ODataErrorMessageName:
                    if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(
                            ref propertiesFoundBitmask,
                            ODataJsonLightReaderUtils.ErrorPropertyBitMask.MessageValue))
                    {
                        return(false);
                    }

                    string message;
                    if (this.TryReadErrorStringPropertyValue(out message))
                    {
                        detail.Message = message;
                    }
                    else
                    {
                        return(false);
                    }

                    break;

                default:
                    // if we find a non-supported property in an inner error, we skip it
                    this.SkipValueInternal();
                    break;
                }

                this.ReadInternal();
            }

            Debug.Assert(
                this.currentBufferedNode.NodeType == JsonNodeType.EndObject,
                "this.currentBufferedNode.NodeType == JsonNodeType.EndObject");

            return(true);
        }
コード例 #8
0
        private bool TryReadErrorDetail(out ODataErrorDetail detail)
        {
            Debug.Assert(
                this.currentBufferedNode.NodeType == JsonNodeType.StartObject,
                "this.currentBufferedNode.NodeType == JsonNodeType.StartObject");
            Debug.Assert(this.parsingInStreamError, "this.parsingInStreamError");
            this.AssertBuffering();

            if (this.currentBufferedNode.NodeType != JsonNodeType.StartObject)
            {
                detail = null;
                return false;
            }

            // {
            ReadInternal();

            detail = new ODataErrorDetail();

            // we expect one of the supported properties for the value (or end-object)
            var propertiesFoundBitmask = ODataJsonLightReaderUtils.ErrorPropertyBitMask.None;
            while (this.currentBufferedNode.NodeType == JsonNodeType.Property)
            {
                var propertyName = (string)this.currentBufferedNode.Value;

                switch (propertyName)
                {
                    case JsonConstants.ODataErrorCodeName:
                        if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(
                                ref propertiesFoundBitmask,
                                ODataJsonLightReaderUtils.ErrorPropertyBitMask.Code))
                        {
                            return false;
                        }

                        string code;
                        if (this.TryReadErrorStringPropertyValue(out code))
                        {
                            detail.ErrorCode = code;
                        }
                        else
                        {
                            return false;
                        }

                        break;

                    case JsonConstants.ODataErrorTargetName:
                        if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(
                                ref propertiesFoundBitmask,
                                ODataJsonLightReaderUtils.ErrorPropertyBitMask.Target))
                        {
                            return false;
                        }

                        string target;
                        if (this.TryReadErrorStringPropertyValue(out target))
                        {
                            detail.Target = target;
                        }
                        else
                        {
                            return false;
                        }

                        break;

                    case JsonConstants.ODataErrorMessageName:
                        if (!ODataJsonLightReaderUtils.ErrorPropertyNotFound(
                                ref propertiesFoundBitmask,
                                ODataJsonLightReaderUtils.ErrorPropertyBitMask.MessageValue))
                        {
                            return false;
                        }

                        string message;
                        if (this.TryReadErrorStringPropertyValue(out message))
                        {
                            detail.Message = message;
                        }
                        else
                        {
                            return false;
                        }

                        break;

                    default:
                        // if we find a non-supported property in an inner error, we skip it
                        this.SkipValueInternal();
                        break;
                }

                this.ReadInternal();
            }

            Debug.Assert(
                this.currentBufferedNode.NodeType == JsonNodeType.EndObject,
                "this.currentBufferedNode.NodeType == JsonNodeType.EndObject");

            return true;
        }