Example #1
0
        private static ErrorRecord GenerateHttpErrorRecord(HttpMessageFormatter httpResponseMessageFormatter,
                                                           HttpRequestMessage httpRequestMessage)
        {
            // Load into buffer to avoid stream already consumed issues.
            httpResponseMessageFormatter.LoadIntoBufferAsync()
            .GetAwaiter()
            .GetResult();
            var currentResponse = httpResponseMessageFormatter.HttpResponseMessage;
            var errorMessage    =
                Resources.ResponseStatusCodeFailure.FormatCurrentCulture(currentResponse.StatusCode,
                                                                         currentResponse.ReasonPhrase);
            var httpException = new HttpResponseException(errorMessage, currentResponse);
            var errorRecord   = new ErrorRecord(httpException, Errors.InvokeGraphHttpResponseException,
                                                ErrorCategory.InvalidOperation, httpRequestMessage);
            var detailMsg = httpResponseMessageFormatter.ReadAsStringAsync()
                            .GetAwaiter()
                            .GetResult();

            if (!string.IsNullOrEmpty(detailMsg))
            {
                errorRecord.ErrorDetails = new ErrorDetails(detailMsg);
            }

            return(errorRecord);
        }
Example #2
0
        /// <summary>
        ///     When -Verbose is specified, print out response status
        /// </summary>
        /// <param name="responseMessageFormatter"></param>
        private void ReportResponseStatus(HttpMessageFormatter responseMessageFormatter)
        {
            responseMessageFormatter.LoadIntoBufferAsync()
            .GetAwaiter()
            .GetResult();
            var contentType    = responseMessageFormatter.HttpResponseMessage.GetContentType();
            var respVerboseMsg = Resources.InvokeGraphResponseVerboseMessage.FormatCurrentCulture(
                responseMessageFormatter.HttpResponseMessage.Content.Headers.ContentLength,
                contentType);

            // If Verbose is specified, will print out Uri and Content Length
            WriteVerbose(respVerboseMsg);
            var responseString = responseMessageFormatter.ReadAsStringAsync()
                                 .GetAwaiter()
                                 .GetResult();

            // If Debug is Specified, will print out the Http Response as a string
            WriteDebug(responseString);
        }
Example #3
0
        /// <summary>
        ///     When -Verbose is specified, print out response status
        /// </summary>
        /// <param name="requestMessageFormatter"></param>
        private void ReportRequestStatus(HttpMessageFormatter requestMessageFormatter)
        {
            requestMessageFormatter.LoadIntoBufferAsync()
            .GetAwaiter()
            .GetResult();
            var requestMessage       = requestMessageFormatter.HttpRequestMessage;
            var requestContentLength = requestMessage.Content?.Headers.ContentLength.Value ?? 0;
            var reqVerboseMsg        = Resources.InvokeGraphRequestVerboseMessage.FormatCurrentCulture(requestMessage.Method,
                                                                                                       requestMessage.RequestUri,
                                                                                                       requestContentLength);

            // If Verbose is specified, will print out Uri and Content Length
            WriteVerbose(reqVerboseMsg);
            var requestString = requestMessageFormatter.ReadAsStringAsync()
                                .GetAwaiter()
                                .GetResult();

            // If Debug is Specified, will print out the Http Request as a string
            WriteDebug(requestString);
        }