Example #1
0
 public void HandleErrors <TResponse, TError>(RealEstatetServicesResponseWrapper <TResponse, TError> result, List <Exception> exceptions)
 {
     if (exceptions.Any())
     {
         HandleException(result, exceptions[0]);
     }
 }
Example #2
0
 public void HandleServiceErrors <TResponse, TError>(RealEstatetServicesResponseWrapper <TResponse, TError> aulaResponse, HttpResponseMessage response)
 {
     if (!response.IsSuccessStatusCode)
     {
         aulaResponse.HttpCode = response.StatusCode;
     }
 }
Example #3
0
        async Task <RealEstatetServicesResponseWrapper <TResponse, TError> > InnerPost <TResponse, TError>(
            string url,
            HttpContent uploadContent,
            CancellationToken ctoken = new CancellationToken())
        {
            RealEstatetServicesResponseWrapper <TResponse, TError> result =
                new RealEstatetServicesResponseWrapper <TResponse, TError>();
            List <Exception> errorContainer = new List <Exception>();

            try
            {
                Uri uri = new Uri(string.Format(url, string.Empty));


                HttpResponseMessage response = await HttpClientManager.Instance.HttpClient.FillAuthenticationHeader().PostAsync(
                    uri,
                    uploadContent,
                    ctoken);

                string content = await response.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(content))
                {
                    result.Response = MapData <TResponse, TError>(content);
                }
                HandleServiceErrors(result, response);
            }
            catch (Exception e)
            {
                errorContainer.Add(e);
            }
            HandleErrors(result, errorContainer);
            return(result);
        }
Example #4
0
        public async Task <RealEstatetServicesResponseWrapper <TResponse, TError> > Get <TResponse, TError>(
            string url,
            object queryObject = null,
            Func <JToken, TResponse> manualDataMapping = null,
            CancellationToken ctoken = new CancellationToken())
        {
            if (queryObject != null)
            {
                string query = ConvertObjectToQueryUrl(queryObject);
                if (string.IsNullOrEmpty(query) == false)
                {
                    if (url.Contains("?") == false)
                    {
                        url += "?";
                    }
                    url += "&" + query;
                }
            }

            RealEstatetServicesResponseWrapper <TResponse, TError> result = new RealEstatetServicesResponseWrapper <TResponse, TError>();
            List <Exception> errorContainer = new List <Exception>();

            try
            {
                Uri uri = new Uri(string.Format(url, string.Empty));

                HttpResponseMessage response = await HttpClientManager.Instance.HttpClient.FillAuthenticationHeader().GetAsync(uri, ctoken).ConfigureAwait(false);

                string content = await response.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(content))
                {
                    result.Response = MapData <TResponse, TError>(content);
                }
                HandleServiceErrors(result, response);
            }
            catch (Exception e)
            {
                errorContainer.Add(e);
            }

            HandleErrors(result, errorContainer);

            return(result);
        }
Example #5
0
        public RealEstatetServicesResponseWrapper <TResponse, TError> HandleException <TResponse, TError>(RealEstatetServicesResponseWrapper <TResponse, TError> result, Exception e)
        {
            if (e is HttpRequestException exception)
            {
                result.Exception = exception;
            }
            else if (e is TaskCanceledException canceledException)
            {
                result.Exception = canceledException;
            }
            else if (e is JsonException jsonException)
            {
                result.Exception = jsonException;
            }
            else
            {
                result.Exception = e;
            }

            return(result);
        }