コード例 #1
0
        /// <summary>
        /// Throw request exception asynchronous.
        /// </summary>
        /// <exception cref="RequestException">
        /// Thrown when a Request error condition occurs.
        /// </exception>
        /// <returns>
        /// A <see cref="Task"/> representing the operation.
        /// </returns>
        internal async Task ThrowRequestExceptionAsync()
        {
            var details = await Splunk.Client.Message.ReadMessagesAsync(this.XmlReader).ConfigureAwait(false);

            RequestException requestException;

            switch (this.Message.StatusCode)
            {
            case HttpStatusCode.BadRequest:
                requestException = new BadRequestException(this.Message, details);
                break;

            case HttpStatusCode.Forbidden:
                requestException = new UnauthorizedAccessException(this.Message, details);
                break;

            case HttpStatusCode.InternalServerError:
                requestException = new InternalServerErrorException(this.Message, details);
                break;

            case HttpStatusCode.NotFound:
                requestException = new ResourceNotFoundException(this.Message, details);
                break;

            case HttpStatusCode.Unauthorized:
                requestException = new AuthenticationFailureException(this.Message, details);
                break;

            default:
                requestException = new RequestException(this.Message, details);
                break;
            }

            throw requestException;
        }
コード例 #2
0
        /// <summary>
        /// Throws a <see cref="RequestException"/> if the current <see cref=
        /// "Response.Message.StatusCode"/> is different than <see cref=
        /// "expected"/>.
        /// </summary>
        /// <param name="expected">
        /// The expected <see cref="HttpStatusCode"/>.
        /// </param>
        /// <returns></returns>
        public async Task EnsureStatusCodeAsync(HttpStatusCode expected)
        {
            var statusCode = this.Message.StatusCode;

            if (statusCode == expected)
            {
                return;
            }

            var details = await Splunk.Client.Message.ReadMessagesAsync(this.XmlReader);

            RequestException requestException;

            switch (statusCode)
            {
            case HttpStatusCode.Forbidden:
                requestException = new UnauthorizedAccessException(this.Message, details);
                break;

            case HttpStatusCode.NotFound:
                requestException = new ResourceNotFoundException(this.Message, details);
                break;

            case HttpStatusCode.Unauthorized:
                requestException = new AuthenticationFailureException(this.Message, details);
                break;

            default:
                requestException = new RequestException(this.Message, details);
                break;
            }

            throw requestException;
        }
コード例 #3
0
ファイル: Response.cs プロジェクト: Netsuye/Splunk-SDK
        /// <summary>
        /// Throw request exception asynchronous.
        /// </summary>
        /// <exception cref="RequestException">
        /// Thrown when a Request error condition occurs.
        /// </exception>
        /// <returns>
        /// A <see cref="Task"/> representing the operation.
        /// </returns>
        internal async Task ThrowRequestExceptionAsync()
        {
            var details = await Splunk.Client.Message.ReadMessagesAsync(this.XmlReader).ConfigureAwait(false);
            RequestException requestException;

            switch (this.Message.StatusCode)
            {
                case HttpStatusCode.BadRequest:
                    requestException = new BadRequestException(this.Message, details);
                    break;
                case HttpStatusCode.Forbidden:
                    requestException = new UnauthorizedAccessException(this.Message, details);
                    break;
                case HttpStatusCode.InternalServerError:
                    requestException = new InternalServerErrorException(this.Message, details);
                    break;
                case HttpStatusCode.NotFound:
                    requestException = new ResourceNotFoundException(this.Message, details);
                    break;
                case HttpStatusCode.Unauthorized:
                    requestException = new AuthenticationFailureException(this.Message, details);
                    break;
                default:
                    requestException = new RequestException(this.Message, details);
                    break;
            }

            throw requestException;
        }
コード例 #4
0
        /// <summary>
        /// Throws a <see cref="RequestException"/> if the current <see cref=
        /// "Response.Message.StatusCode"/> is different than <see cref=
        /// "expected"/>.
        /// </summary>
        /// <param name="expected">
        /// The expected <see cref="HttpStatusCode"/>.
        /// </param>
        /// <returns></returns>
        public async Task EnsureStatusCodeAsync(HttpStatusCode expected)
        {
            var statusCode = this.Message.StatusCode;

            if (statusCode == expected)
                return;

            var details = await Splunk.Client.Message.ReadMessagesAsync(this.XmlReader);
            RequestException requestException;

            switch (statusCode)
            {
                case HttpStatusCode.Forbidden:
                    requestException = new UnauthorizedAccessException(this.Message, details);
                    break;
                case HttpStatusCode.NotFound:
                    requestException = new ResourceNotFoundException(this.Message, details);
                    break;
                case HttpStatusCode.Unauthorized:
                    requestException = new AuthenticationFailureException(this.Message, details);
                    break;
                default:
                    requestException = new RequestException(this.Message, details);
                    break;
            }

            throw requestException;
        }