http: add OnException
This commit is contained in:
parent
210c8de1ed
commit
c675cd221e
1 changed files with 9 additions and 3 deletions
|
@ -50,6 +50,11 @@ public sealed class HttpServer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<HttpRequest, HttpResponse>? OnResponse;
|
public event Action<HttpRequest, HttpResponse>? OnResponse;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when a request causes an exception.
|
||||||
|
/// </summary>
|
||||||
|
public event Action<IPEndPoint, Exception>? OnException;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maximum time the socket may be inactive before it is presumed dead and closed.
|
/// The maximum time the socket may be inactive before it is presumed dead and closed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -179,12 +184,12 @@ public sealed class HttpServer
|
||||||
await new HttpResponse(400, e.Message).WriteTo(httpStream).WaitAsync(Timeout);
|
await new HttpResponse(400, e.Message).WriteTo(httpStream).WaitAsync(Timeout);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
break;
|
throw;
|
||||||
}
|
}
|
||||||
catch (TimeoutException)
|
catch (TimeoutException)
|
||||||
{
|
{
|
||||||
//Timeout
|
//Timeout
|
||||||
break;
|
throw;
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
@ -203,10 +208,11 @@ public sealed class HttpServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
//Swallow exceptions to prevent the server from crashing.
|
//Swallow exceptions to prevent the server from crashing.
|
||||||
//When debugging, use a debugger to break on exceptions.
|
//When debugging, use a debugger to break on exceptions.
|
||||||
|
OnException?.Invoke(endpoint, e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue