Ejemplo n.º 1
0
        private async Task <bool> FetchIsOn(IFeatureEvaluationRequest request, CancellationToken token = default)
        {
            var httpRequest = request.ToHttpRequestMessage();

            if (!token.IsCancellationRequested)
            {
                try
                {
                    var response = await this._client.SendAsync(httpRequest, token);

                    if (response.IsSuccessStatusCode)
                    {
                        return(await response.Content.ReadFromJsonAsync <bool>(this._jsonOptions, token));
                    }

                    var content = await response.Content.ReadAsStringAsync(token);

                    var e = new FailedToCommunicateWithEvaluationsException(response, content);
                    throw e;
                }
                catch (Exception e)
                {
                    this._logger.LogError(e, $"An error occurred while requesting if feature was On ${e.Message}.");
                    throw;
                }
            }

            throw new OperationCanceledException("Cancellation was requested while attempting to request feature IsOn.");
        }