mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-28 23:52:36 +01:00
Merge pull request #580 from Cyberboss/SuppressRequestCancellation
Supress errors from cancelled requests. Log them as debug
This commit is contained in:
@@ -203,7 +203,14 @@ namespace Tgstation.Server.Host.Controllers
|
||||
|
||||
Logger.LogDebug("Request made by User ID {0}. Api version: {1}. User-Agent: {2}. Type: {3}. Route {4}{5} to Instance {6}", AuthenticationContext?.User.Id.ToString(CultureInfo.InvariantCulture), ApiHeaders.ApiVersion, ApiHeaders.UserAgent, Request.Method, Request.Path, Request.QueryString, ApiHeaders.InstanceId);
|
||||
|
||||
await base.OnActionExecutionAsync(context, next).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await base.OnActionExecutionAsync(context, next).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
Logger.LogDebug("Request cancelled! Exception: {0}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +244,8 @@ namespace Tgstation.Server.Host.Core
|
||||
|
||||
applicationBuilder.UseDbConflictHandling();
|
||||
|
||||
applicationBuilder.UseCancelledRequestSuppression();
|
||||
|
||||
applicationBuilder.UseMvc();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,5 +35,23 @@ namespace Tgstation.Server.Host.Core
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suppress TaskCanceledException warnings when a user aborts a request
|
||||
/// </summary>
|
||||
/// <param name="applicationBuilder">The <see cref="IApplicationBuilder"/> to configure</param>
|
||||
public static void UseCancelledRequestSuppression(this IApplicationBuilder applicationBuilder)
|
||||
{
|
||||
if (applicationBuilder == null)
|
||||
throw new ArgumentNullException(nameof(applicationBuilder));
|
||||
applicationBuilder.Use(async (context, next) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
await next().ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user