1
0
Fork 0

Add error handling to root HttpListener handler

This commit is contained in:
Starbeamrainbowlabs 2016-07-16 20:57:59 +01:00
parent 60b7560d21
commit 2d020ab168
2 changed files with 19 additions and 6 deletions

View File

@ -4,7 +4,6 @@ using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using System.Xml;
using System.Reflection;
@ -78,10 +77,24 @@ namespace GalleryShare
/// <param name="cycle">The Http request to handle.</param>
private async Task Handle(HttpListenerContext cycle)
{
await router.RouteRequest(cycle);
logCycle(cycle);
cycle.Response.Close();
try
{
await router.RouteRequest(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();
}
}
private string GetFullReqestedPath(string rawUrl)

View File

@ -13,7 +13,7 @@ namespace GalleryShare.RequestRouter
public class MasterHttpRouter
{
public bool DebugMode = true;
public bool DebugMode = false;
List<IRequestRoute> requestRoutes = new List<IRequestRoute>();
UrlPathTransformer urlTransformer;