Exemplo n.º 1
0
 private async Task RunInternalAsync(Func <Task> torun)
 {
     if (!Settings.CatchErrors)
     {
         await torun().ConfigureAwait(false);
     }
     else
     {
         try
         {
             await torun().ConfigureAwait(false);
         }
         catch (Exception e)
         {
             OnErrorCaught?.Invoke(this, e);
         }
     }
 }
Exemplo n.º 2
0
 private async Task <T> RunInternalAsync <T>(Func <Task <T> > torun)
 {
     if (!Settings.CatchErrors)
     {
         return(await torun().ConfigureAwait(false));
     }
     else
     {
         try
         {
             return(await torun().ConfigureAwait(false));
         }
         catch (Exception e)
         {
             OnErrorCaught?.Invoke(this, e);
         }
     }
     return(default(T));
 }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> SendRequestOrFailAsync(HttpRequestMessage request, HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead)
        {
            var response = await SendRequestAsync(request, httpCompletionOption).ConfigureAwait(false);

            if (response.IsSuccessStatusCode)
            {
                return(response);
            }
            else
            {
                if (Settings.ThrowOnFail)
                {
                    throw new HttpFailException(response);
                }
                else
                {
                    OnErrorCaught?.Invoke(this, new HttpFailException(response));
                }
            }
            return(null);
        }