Esempio n. 1
0
        /// <summary>
        /// Gets the json response from the api endpoint and deserializes to the given type T
        /// </summary>
        /// <typeparam name="T">The type to deserialize</typeparam>
        /// <param name="resource">The web url to query</param>
        /// <returns>A new data object will be returned on success or an error will be thrown</returns>
        private async Task <T> GetResourceAsync <T>(string resource) where T : PropertyBagBase
        {
            var request  = new HttpRequestMessage(HttpMethod.Get, resource);
            var response = await this.httpClient.SendAsync(request).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                var payload = JsonConvert.DeserializeObject <T>(content);

                if (payload.ErrorInfo != null)
                {
                    throw ApiException.CreateExceptionFromExceptionInfo(payload.ErrorInfo);
                }

                return(payload);
            }

            return(default);