2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00

Handle exceptions during async http requests.

This commit is contained in:
Xjph 2023-01-18 21:38:24 -03:30
parent cacaa98033
commit 52aa9fb1e5

View File

@ -77,7 +77,14 @@ namespace Observatory.Herald
}
};
using var response = await httpClient.PostAsync(ApiEndpoint + "/Speak", request);
var requestTask = httpClient.PostAsync(ApiEndpoint + "/Speak", request);
requestTask.Wait(5000);
if (requestTask.IsFaulted)
throw new PluginException("Herald", "Error retrieving voice audio.", requestTask.Exception);
using var response = await requestTask;
if (response.IsSuccessStatusCode)
{
@ -140,9 +147,16 @@ namespace Observatory.Herald
{ "obs-plugin", "herald" },
{ "api-key", ApiKey }
}
};
};
var response = httpClient.SendAsync(request).Result;
var requestTask = httpClient.SendAsync(request);
requestTask.Wait(1000);
if (requestTask.IsFaulted)
throw new PluginException("Herald", "Unable to retrieve available voices.", requestTask.Exception);
var response = requestTask.Result;
if (response.IsSuccessStatusCode)
{