Handle exceptions during async http requests.
This commit is contained in:
parent
cacaa98033
commit
52aa9fb1e5
1 changed files with 17 additions and 3 deletions
|
|
@ -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)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
|
|
@ -140,9 +147,16 @@ namespace Observatory.Herald
|
||||||
{ "obs-plugin", "herald" },
|
{ "obs-plugin", "herald" },
|
||||||
{ "api-key", ApiKey }
|
{ "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)
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue