Esempio n. 1
0
        public ResponceModel <TOut, TError> GetRequest(string url, string checkfield, string authScheme = null, byte[] credentials = null)
        {
            TError error;
            var    apiResponce = new ResponceModel <TOut, TError>();

            var responceResult = Client(url, authScheme, credentials);

            try
            {
                var result = Parsers.ParseOutput(responceResult, typeof(TOut).Name);

                try
                {
                    error = JsonConvert.DeserializeObject <TError>(result);
                    if (Reflections.IsPropertyNull(error, checkfield))
                    {
                        throw new Exception();
                    }

                    apiResponce.Responce          = JsonConvert.DeserializeObject <TOut>(result);
                    apiResponce.Status.statusCode = HttpStatusCode.OK;

                    return(apiResponce);
                }
                catch (Exception e)
                {
                    error = JsonConvert.DeserializeObject <TError>(result);

                    apiResponce.Status.statusCode = HttpStatusCode.BadRequest;
                    apiResponce.Status.message    = result;
                    apiResponce.Status.error      = error;

                    return(apiResponce);
                }
            }
            catch (Exception e)
            {
                apiResponce.Status.statusCode = HttpStatusCode.InternalServerError;
                apiResponce.Status.message
                    = $"ApiConnector fatal error\n Model: {typeof(TOut).Name}\n Link: {url}\n Exception message: {e.Message.ToString()}";

                return(apiResponce);
            }
        }