OperationCanceledException
Closed this issue · 0 comments
dlidstrom commented
diff --git a/Snittlistan.Web/App_Start/WebApiConfig.cs b/Snittlistan.Web/App_Start/WebApiConfig.cs
index 3cf35ae3..706fc6d5 100644
--- a/Snittlistan.Web/App_Start/WebApiConfig.cs
+++ b/Snittlistan.Web/App_Start/WebApiConfig.cs
@@ -1,4 +1,6 @@
+using System.Net;
+using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web.Http;
using System.Web.Http.ExceptionHandling;
@@ -9,6 +11,7 @@ using Snittlistan.Web.Infrastructure.Attributes;
#nullable enable
namespace Snittlistan.Web;
+
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
@@ -27,5 +30,15 @@ public static class WebApiConfig
config.Filters.Add(new ValidateModelAttribute());
config.Formatters.Add(new ICalFormatter());
config.MessageHandlers.Add(new OutlookAgentMessageHandler());
+ config.MessageHandlers.Add(new CanceledTaskMessageHandler());
+ }
+
+ private class CanceledTaskMessageHandler : DelegatingHandler
+ {
+ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
+ return cancellationToken.IsCancellationRequested ? new HttpResponseMessage(HttpStatusCode.InternalServerError) : response;
+ }
}
}