Esempio n. 1
0
        /// <summary>
        /// HandleNonSuccessfulResponse will only be called to process responses return from service that are not 2xx.
        /// If this happens, throw OciException.
        /// </summary>
        /// <param name="responseMessage">An HttpResponseMessage.</param>
        /// <exception>Throws OciException if error code and message are retrieved, or throws any exception from ReadEntityInternal.</exception>
        public static void HandleNonSuccessfulResponse(HttpResponseMessage responseMessage)
        {
            var responseOpcRequestId = HeaderUtils.GetFirstorDefaultHeaderValue(responseMessage.Headers, "opc-request-id");

            try
            {
                ErrorCodeAndMessage errorCodeAndMessage = ReadEntityInternal <ErrorCodeAndMessage>(responseMessage, responseOpcRequestId);
                throw new OciException(
                          responseMessage.StatusCode,
                          errorCodeAndMessage?.Message ?? responseMessage.ReasonPhrase ?? DEFAULT_OCI_EXCEPTION_MESSAGE,
                          errorCodeAndMessage?.Code ?? DEFAULT_OCI_EXCEPTION_SERVICE_CODE,
                          responseOpcRequestId);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 2
0
        /// <summary>Reads content from HttpResponseMessage and converts it into SDK response object.</summary>
        /// <param name="response">An HttpResponseMessage.</param>
        /// <returns>An SDK response object.</returns>
        /// <exception>Throws any exception from ReadEntityInternal.</exception>
        public static T ReadEntity <T>(HttpResponseMessage response)
        {
            var opcRequestId = HeaderUtils.GetFirstorDefaultHeaderValue(response.Headers, "opc-request-id");

            try
            {
                if (typeof(T) == typeof(System.IO.Stream))
                {
                    // Handle binary response
                    return((T)(object)response.Content.ReadAsStreamAsync().Result);
                }

                // Handle JSONResponse.
                return(ReadEntityInternal <T>(response, opcRequestId));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public void TestFromValue(dynamic value)
        {
            var convertedValue = HeaderUtils.FromValue(value);

            Assert.True(convertedValue.GetType().Equals(typeof(string)));
        }
        public void TestToValue(string strValue, Type type)
        {
            var convertedValue = HeaderUtils.ToValue(strValue, type);

            Assert.True(type.Equals(convertedValue.GetType()));
        }