diff --git a/Pilz.Net/Api/ApiServer.cs b/Pilz.Net/Api/ApiServer.cs index ea7ec94..fe05fde 100644 --- a/Pilz.Net/Api/ApiServer.cs +++ b/Pilz.Net/Api/ApiServer.cs @@ -280,31 +280,27 @@ public class ApiServer : IApiServer if (AllowMultipleRequests) Receive(); - // Cancel if we don't have a context - if (context is null) - { - FreeSlot(); - return; - } - // Check context - Log.Info("Request retrived for " + context.Request.RawUrl); - OnCheckContext?.Invoke(this, new(context)); var success = false; - try + if (context is not null) { - CheckContext(context); - success = true; - } - catch (Exception ex) - { - Log.Error("Error checking context", ex); - if (DebugMode) - throw; - } - finally - { - OnCheckContextCompleted?.Invoke(this, new(context)); + Log.Info("Request retrived for " + context.Request.RawUrl); + OnCheckContext?.Invoke(this, new(context)); + try + { + CheckContext(context); + success = true; + } + catch (Exception ex) + { + Log.Error("Error checking context", ex); + if (DebugMode) + throw; + } + finally + { + OnCheckContextCompleted?.Invoke(this, new(context)); + } } // Try closing the request on fail @@ -312,7 +308,7 @@ public class ApiServer : IApiServer { try { - context.Response.Close(); + context?.Response.Close(); } catch (Exception) {