/// <exception cref="ApiException"></exception> private static async Task <HttpResponseMessage> SendCoreAsync(this HttpClient httpClient, HttpRequestMessage requestMessage, ApiRequest request) { try { return(await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false)); } catch (TaskCanceledException ex) when(ex.InnerException is TimeoutException) { // Handle timeout. throw ApiExceptions.ClientTimeout(request: request, innerException: ex); } catch (TaskCanceledException ex) when(ex.InnerException is SocketException) { throw ApiExceptions.ApiNotAvailable(request: request, innerException: ex); } catch (TaskCanceledException ex) { // Handle cancellation. throw ApiExceptions.RequestCanceled(request: request, innerException: ex); } //TODO: when using .net 5 //catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.NotFound) //{ // // Handle 404 // Console.WriteLine("Not found: " + ex.Message); //} catch (OperationCanceledException ex) { throw ApiExceptions.ApiNotAvailable(request, ex); } catch (Exception ex) { throw ApiExceptions.ClientUnkownError(request: request, innerException: ex); } }