internal ErrorHandlingHttpClient(ErrorHandlingHttpClientArgs <T> args)
 {
     this.httpClient           = CreateHttpClient(args);
     this.deserializer         = args.Deserializer ?? JsonResponseDeserializer.Instance;
     this.errorResponseHandler = args.ErrorResponseHandler.ThrowIfNull(
         nameof(args.ErrorResponseHandler));
     this.requestExceptionHandler = args.RequestExceptionHandler.ThrowIfNull(
         nameof(args.RequestExceptionHandler));
     this.deserializeExceptionHandler = args.DeserializeExceptionHandler.ThrowIfNull(
         nameof(args.DeserializeExceptionHandler));
 }
        private static HttpClient CreateHttpClient(ErrorHandlingHttpClientArgs <T> args)
        {
            var clientArgs = new CreateHttpClientArgs();
            var credential = args.Credential;

            if (credential != null)
            {
                clientArgs.Initializers.Add(credential);
            }

            var retry = args.RetryOptions;

            if (retry != null)
            {
                clientArgs.Initializers.Add(new RetryHttpClientInitializer(retry));
            }

            var clientFactory = args.HttpClientFactory.ThrowIfNull(nameof(args.HttpClientFactory));

            return(clientFactory.CreateHttpClient(clientArgs));
        }
Esempio n. 3
0
        internal ErrorHandlingHttpClient(ErrorHandlingHttpClientArgs <T> args)
        {
            var credential    = args.Credential;
            var clientFactory = args.HttpClientFactory.ThrowIfNull(nameof(args.HttpClientFactory));

            if (credential != null)
            {
                this.httpClient = clientFactory.CreateAuthorizedHttpClient(credential);
            }
            else
            {
                this.httpClient = clientFactory.CreateDefaultHttpClient();
            }

            this.deserializer         = args.Deserializer ?? JsonResponseDeserializer.Instance;
            this.errorResponseHandler = args.ErrorResponseHandler.ThrowIfNull(
                nameof(args.ErrorResponseHandler));
            this.requestExceptionHandler = args.RequestExceptionHandler.ThrowIfNull(
                nameof(args.RequestExceptionHandler));
            this.deserializeExceptionHandler = args.DeserializeExceptionHandler.ThrowIfNull(
                nameof(args.DeserializeExceptionHandler));
        }