Improve error handling

This commit is contained in:
Nikolaj Olsson 2024-04-15 21:19:02 +02:00
parent d42a974457
commit 7d56cf185f

View File

@ -141,6 +141,12 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.TryAddWithoutValidation(SecurityHeaderName, apiKey);
var response = httpClient.PostAsync(tokenEndpoint, new StringContent(string.Empty)).Result;
var result = response.Content.ReadAsStringAsync().Result;
if (!response.IsSuccessStatusCode)
{
SeLogger.Error($"{StaticName}: Error getting access token via {tokenEndpoint} and API key {apiKey}: {result}");
}
return response.Content.ReadAsStringAsync().Result;
}