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>
|
||||
public event Action<HttpRequest, HttpResponse>? OnResponse;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a request causes an exception.
|
||||
/// </summary>
|
||||
public event Action<IPEndPoint, Exception>? OnException;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum time the socket may be inactive before it is presumed dead and closed.
|
||||
/// </summary>
|
||||
|
@ -179,12 +184,12 @@ public sealed class HttpServer
|
|||
await new HttpResponse(400, e.Message).WriteTo(httpStream).WaitAsync(Timeout);
|
||||
}
|
||||
catch { }
|
||||
break;
|
||||
throw;
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
//Timeout
|
||||
break;
|
||||
throw;
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
|
@ -203,10 +208,11 @@ public sealed class HttpServer
|
|||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
//Swallow exceptions to prevent the server from crashing.
|
||||
//When debugging, use a debugger to break on exceptions.
|
||||
OnException?.Invoke(endpoint, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue