|
@@ -7,7 +7,7 @@ namespace Tr.Sdk;
|
|
|
|
|
|
public class TrClient : ITrClient, IDisposable
|
|
|
{
|
|
|
- private readonly RestClient _client;
|
|
|
+ private RestClient _client;
|
|
|
private readonly string _baseUrl;
|
|
|
private readonly string _apiKey;
|
|
|
private readonly string _apiSecret;
|
|
@@ -22,7 +22,7 @@ public class TrClient : ITrClient, IDisposable
|
|
|
Authenticator = new TrAuthenticator(baseUrl, apiKey, apiSecret)
|
|
|
};
|
|
|
_client = new RestClient(options);
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -41,25 +41,22 @@ public class TrClient : ITrClient, IDisposable
|
|
|
try
|
|
|
{
|
|
|
var response = await _client.ExecuteAsync<TResponse>(req, cancellationToken);
|
|
|
- if (!response?.IsSuccessful ?? false)
|
|
|
+
|
|
|
+ if (response?.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
|
|
{
|
|
|
- if(response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
|
|
+ _client.Dispose();
|
|
|
+ var options = new RestClientOptions(_baseUrl)
|
|
|
{
|
|
|
- //TODO 清除Token
|
|
|
- var options = new RestClientOptions(_baseUrl)
|
|
|
- {
|
|
|
- Authenticator = new TrAuthenticator(_baseUrl, _apiKey, _apiSecret)
|
|
|
- };
|
|
|
- RestClient _newClient = new RestClient(options);
|
|
|
- response = await _newClient.ExecuteAsync<TResponse>(req, cancellationToken);
|
|
|
- if (!response?.IsSuccessful ?? false)
|
|
|
- throw new HttpRequestException($"请求呼叫中心服务失败, HttpCode: {response.StatusCode}, Error: {response.ErrorMessage}");
|
|
|
+ Authenticator = new TrAuthenticator(_baseUrl, _apiKey, _apiSecret)
|
|
|
+ };
|
|
|
+ _client = new RestClient(options);
|
|
|
|
|
|
- return response.Data;
|
|
|
- }
|
|
|
- throw new HttpRequestException($"请求呼叫中心服务失败, HttpCode: {response.StatusCode}, Error: {response.ErrorMessage}");
|
|
|
+ response = await _client.ExecuteAsync<TResponse>(req, cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ if (!response?.IsSuccessful ?? false)
|
|
|
+ throw new HttpRequestException($"请求呼叫中心服务失败, HttpCode: {response.StatusCode}, Error: {response.ErrorMessage}");
|
|
|
+
|
|
|
return response.Data;
|
|
|
}
|
|
|
catch (Exception e)
|