예제 #1
0
        private async Task EnsureResult(HttpResponseMessage response)
        {
            string resultString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if ((int)response.StatusCode < 200 || (int)response.StatusCode >= 300)
            {
                Exceptions.VoucherifyClientException exception;

                try
                {
                    exception = this.serializerException.Deserialize(resultString);
                    exception = new Exceptions.VoucherifyClientException(exception.Message, exception.Code, exception.Details);
                }
                catch
                {
                    exception = new Exceptions.VoucherifyClientException(response.StatusCode.ToString(), (int)response.StatusCode, resultString);
                }

                throw exception;
            }
        }
예제 #2
0
        private async Task <TResult> EnsureResult <TResult>(HttpResponseMessage response)
            where TResult : class
        {
            string resultString = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            if ((int)response.StatusCode < 200 || (int)response.StatusCode >= 300)
            {
                Exceptions.VoucherifyClientException exception;

                try
                {
                    exception = this.serializerException.Deserialize(resultString);
                    exception = new Exceptions.VoucherifyClientException(exception.Message, exception.Code, exception.Details, exception.Key);
                }
                catch
                {
                    exception = new Exceptions.VoucherifyClientException(response.StatusCode.ToString(), (int)response.StatusCode, resultString, string.Empty);
                }

                throw exception;
            }

            return(new Serialization.JsonSerializer <TResult>(this.converters).Deserialize(resultString));
        }