improve api server error handling
This commit is contained in:
@@ -85,7 +85,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
|
|
||||||
protected void ListenerCallback(IAsyncResult result)
|
protected void ListenerCallback(IAsyncResult result)
|
||||||
{
|
{
|
||||||
HttpListenerContext context;
|
HttpListenerContext? context;
|
||||||
|
|
||||||
// Skip if not lisstening anymore
|
// Skip if not lisstening anymore
|
||||||
if (!httpListener.IsListening)
|
if (!httpListener.IsListening)
|
||||||
@@ -96,15 +96,20 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
{
|
{
|
||||||
context = httpListener.EndGetContext(result);
|
context = httpListener.EndGetContext(result);
|
||||||
}
|
}
|
||||||
catch (HttpListenerException)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
return;
|
Log.ErrorFormat("Error at getting context: ", ex.ToString());
|
||||||
|
context = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Immitatly listen for new request
|
// Immitatly listen for new request
|
||||||
if (AllowMultipleRequests)
|
if (AllowMultipleRequests)
|
||||||
Receive();
|
Receive();
|
||||||
|
|
||||||
|
// Cancel if we don't have a context
|
||||||
|
if (context is null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Check context
|
// Check context
|
||||||
OnCheckContext?.Invoke(this, new(context));
|
OnCheckContext?.Invoke(this, new(context));
|
||||||
try
|
try
|
||||||
@@ -113,7 +118,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error(ex.ToString());
|
Log.ErrorFormat("Error at checking context: ", ex.ToString());
|
||||||
if (DebugMode)
|
if (DebugMode)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user