Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions src/UniGetUI.Interface.IpcApi/IpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,20 +1181,31 @@ private async Task<string> 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<T?> ReadAuthenticatedJsonAsync<T>(
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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(
Expand Down
Loading