コード例 #1
0
 protected virtual Task InitializeAsync(DownstreamRequest request)
 {
     return(Task.CompletedTask);
 }
コード例 #2
0
        public static async Task <DownstreamResponse> FromHttpResponseAsync(HttpResponseMessage httpResponse, DownstreamRequest request)
        {
            var response = AbstractTypeFactory <DownstreamResponse> .TryCreateInstance(request.Scenario.Connection.ResponseType.Name);

            response.HttpResponse = httpResponse;

            // try to read content
            var content = await httpResponse.Content.ReadAsStringAsync();

            response.Raw = content;

            // some HTTP error - try to parse body as JSON but allow non-JSON as well
            if (httpResponse.IsSuccessStatusCode)
            {
                try
                {
                    if (content != null)
                    {
                        response.Json = JObject.Parse(content);
                    }
                    await response.InitializeAsync(request);
                }
                catch (Exception ex)
                {
                    response.ErrorType = ResponseErrorType.Exception;
                    response.Exception = ex;
                }
            }
            else
            {
                response.ErrorType = httpResponse.StatusCode == HttpStatusCode.BadRequest ? ResponseErrorType.Application : ResponseErrorType.Http;
            }
            return(response);
        }