diff --git a/src/UniGetUI.Interface.IpcApi/IpcClient.cs b/src/UniGetUI.Interface.IpcApi/IpcClient.cs index 1931b8e6f5..4299316703 100644 --- a/src/UniGetUI.Interface.IpcApi/IpcClient.cs +++ b/src/UniGetUI.Interface.IpcApi/IpcClient.cs @@ -1181,20 +1181,31 @@ private async Task SendAsync( HttpContent? requestContent = null ) { - using var timeout = new CancellationTokenSource(GetRequestTimeout(method, relativePath)); + TimeSpan requestTimeout = GetRequestTimeout(method, relativePath); + using var timeout = new CancellationTokenSource(requestTimeout); using var request = new HttpRequestMessage(method, BuildRelativeUri(relativePath, queryParameters)); request.Content = requestContent; - using var response = await _httpClient.SendAsync(request, timeout.Token); - string content = await response.Content.ReadAsStringAsync(); + try + { + using var response = await _httpClient.SendAsync(request, timeout.Token); + string content = await response.Content.ReadAsStringAsync(timeout.Token); - if (!response.IsSuccessStatusCode) + if (!response.IsSuccessStatusCode) + { + throw new InvalidOperationException( + string.IsNullOrWhiteSpace(content) ? response.ReasonPhrase : content + ); + } + + return content; + } + catch (OperationCanceledException ex) when (timeout.IsCancellationRequested) { - throw new InvalidOperationException( - string.IsNullOrWhiteSpace(content) ? response.ReasonPhrase : content + throw new TimeoutException( + $"UniGetUI did not answer {method.Method} {relativePath} within {requestTimeout.TotalSeconds:0} seconds.", + ex ); } - - return content; } private async Task ReadAuthenticatedJsonAsync( @@ -1474,7 +1485,7 @@ private static TimeSpan GetRequestTimeout(HttpMethod method, string relativePath { return method == HttpMethod.Post ? TimeSpan.FromMinutes(5) - : TimeSpan.FromSeconds(30); + : TimeSpan.FromMinutes(2); } if (IpcHttpRoutes.StartsWith(relativePath, "/bundles/install")) @@ -1536,7 +1547,8 @@ private static bool IsConnectivityException(Exception exception) return exception is HttpRequestException or IOException or TaskCanceledException - or OperationCanceledException; + or OperationCanceledException + or TimeoutException; } private static IpcEndpointRegistration? SelectLiveRegistration(