mirror of
https://gitlab.com/sbrl/GalleryShare.git
synced 2018-06-12 22:45:16 +00:00
Add error handling to root HttpListener handler
This commit is contained in:
parent
60b7560d21
commit
2d020ab168
2 changed files with 19 additions and 6 deletions
|
@ -4,7 +4,6 @@ using System.Threading.Tasks;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Remoting.Messaging;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -77,12 +76,26 @@ namespace GalleryShare
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cycle">The Http request to handle.</param>
|
/// <param name="cycle">The Http request to handle.</param>
|
||||||
private async Task Handle(HttpListenerContext cycle)
|
private async Task Handle(HttpListenerContext cycle)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
await router.RouteRequest(cycle);
|
await router.RouteRequest(cycle);
|
||||||
|
|
||||||
logCycle(cycle);
|
logCycle(cycle);
|
||||||
|
}
|
||||||
|
catch(Exception error)
|
||||||
|
{
|
||||||
|
Console.WriteLine("[{0}] [{1}] [Error] {2} ({3})",
|
||||||
|
DateTime.Now.ToString("hh:m tt"),
|
||||||
|
cycle.Request.RemoteEndPoint,
|
||||||
|
cycle.Request.RawUrl,
|
||||||
|
error.Message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
cycle.Response.Close();
|
cycle.Response.Close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string GetFullReqestedPath(string rawUrl)
|
private string GetFullReqestedPath(string rawUrl)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace GalleryShare.RequestRouter
|
||||||
|
|
||||||
public class MasterHttpRouter
|
public class MasterHttpRouter
|
||||||
{
|
{
|
||||||
public bool DebugMode = true;
|
public bool DebugMode = false;
|
||||||
|
|
||||||
List<IRequestRoute> requestRoutes = new List<IRequestRoute>();
|
List<IRequestRoute> requestRoutes = new List<IRequestRoute>();
|
||||||
UrlPathTransformer urlTransformer;
|
UrlPathTransformer urlTransformer;
|
||||||
|
|
Loading…
Reference in a new issue