mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-22 20:47:28 +01:00
Fix a CA1506 warning
This commit is contained in:
@@ -405,7 +405,7 @@ namespace Tgstation.Server.Client
|
||||
if (loggingConfigureAction != null)
|
||||
hubConnectionBuilder.ConfigureLogging(loggingConfigureAction);
|
||||
|
||||
async ValueTask<IAsyncDisposable> AttemptConnect()
|
||||
async ValueTask<HubConnection> AttemptConnect()
|
||||
{
|
||||
hubConnection = hubConnectionBuilder.Build();
|
||||
try
|
||||
@@ -454,25 +454,7 @@ namespace Tgstation.Server.Client
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return await AttemptConnect();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
// status code is not in netstandard
|
||||
var propertyInfo = ex.GetType().GetProperty("StatusCode");
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
var statusCode = (HttpStatusCode)propertyInfo.GetValue(ex);
|
||||
if (statusCode != HttpStatusCode.Unauthorized)
|
||||
throw;
|
||||
}
|
||||
|
||||
await RefreshToken(cancellationToken);
|
||||
|
||||
return await AttemptConnect();
|
||||
}
|
||||
return await WrapHubInitialConnectAuthRefresh(AttemptConnect, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -594,6 +576,35 @@ namespace Tgstation.Server.Client
|
||||
}
|
||||
#pragma warning restore CA1506
|
||||
|
||||
/// <summary>
|
||||
/// Wrap a hub connection attempt via a <paramref name="connectFunc"/> with proper token refreshing.
|
||||
/// </summary>
|
||||
/// <param name="connectFunc">The <see cref="HubConnection"/> <see cref="Func{TResult}"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
|
||||
/// <returns>A <see cref="ValueTask{TResult}"/> resulting in the connected <see cref="HubConnection"/>.</returns>
|
||||
async ValueTask<HubConnection> WrapHubInitialConnectAuthRefresh(Func<ValueTask<HubConnection>> connectFunc, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await connectFunc();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
// status code is not in netstandard
|
||||
var propertyInfo = ex.GetType().GetProperty("StatusCode");
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
var statusCode = (HttpStatusCode)propertyInfo.GetValue(ex);
|
||||
if (statusCode != HttpStatusCode.Unauthorized)
|
||||
throw;
|
||||
}
|
||||
|
||||
await RefreshToken(cancellationToken);
|
||||
|
||||
return await connectFunc();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main request method.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user