Пример #1
0
        private async static Task <SdrcFlurHttpResponse <T> > SdrcHttpCallAsync <T>(string request, Func <Task <T> > httpCallAsync)
        {
            var sdrcResponse = new SdrcFlurHttpResponse <T>();

            try
            {
                sdrcResponse.Request = request;
                sdrcResponse.Data    = await httpCallAsync().ConfigureAwait(false);

                sdrcResponse.StatusCode = HttpStatusCode.OK;
            }
            catch (FlurlHttpTimeoutException ex)
            {
                sdrcResponse.StatusCode = (HttpStatusCode)SdrcHttpStatusCode.FlurlTimeOut;
                sdrcResponse.Exception  = ex;
            }
            catch (FlurlHttpException ex1)
            {
                if (ex1.InnerException is TaskCanceledException)
                {
                    sdrcResponse.StatusCode = ex1.Call.Response?.StatusCode ?? (HttpStatusCode)(SdrcHttpStatusCode.FlurlTaskCanceled);
                }
                else
                {
                    sdrcResponse.StatusCode = ex1.Call.Response?.StatusCode ?? (HttpStatusCode)(SdrcHttpStatusCode.FlurlException);
                }
                if (ex1.Call?.Response?.Content != null)
                {
                    try
                    {
                        sdrcResponse.Message = await ex1.Call.Response.Content.ReadAsStringAsync().ConfigureAwait(false);
                    }
                    catch // (Exception ex11)
                    {
                        // sdrcResponse.Message = ex11.Message;
                    }
                }
                sdrcResponse.Exception = ex1;
            }
            catch (Exception ex3)
            {
                sdrcResponse.StatusCode = (HttpStatusCode)(SdrcHttpStatusCode.Exception);
                sdrcResponse.Exception  = ex3;
            }
            return(sdrcResponse.MarkReceived());
        }
Пример #2
0
 public static bool HasException(this SdrcFlurHttpResponse thisValue)
 => thisValue.Exception != null;
Пример #3
0
 public static bool IsHttpStatusCodeException(this SdrcFlurHttpResponse thisValue)
 => thisValue.StatusCode.IsHttpStatusCode((HttpStatusCode)SdrcHttpStatusCode.Exception);
Пример #4
0
 public static bool IsHttpStatusCodeFlurlTaskCanceled(this SdrcFlurHttpResponse thisValue)
 => thisValue.StatusCode.IsHttpStatusCode((HttpStatusCode)SdrcHttpStatusCode.FlurlTaskCanceled);
Пример #5
0
 public static bool IsHttpStatusCodeFlurlTimeout(this SdrcFlurHttpResponse thisValue)
 => thisValue.StatusCode.IsHttpStatusCode((HttpStatusCode)SdrcHttpStatusCode.FlurlTimeOut);
Пример #6
0
 public static bool IsHttpStatusCodeUndefined(this SdrcFlurHttpResponse thisValue)
 => thisValue.StatusCode.IsHttpStatusCode((HttpStatusCode)SdrcHttpStatusCode.Undefined);
Пример #7
0
 public static bool IsHttpStatusCodeOK(this SdrcFlurHttpResponse thisValue)
 => thisValue.StatusCode.IsHttpStatusCode(HttpStatusCode.OK);