public Reply HandleRequest(Request request)
{
if (RequestObserver != null)
RequestObserver.ObserveRequest(request);
if (Debugger.IsAttached)
{
try
{
Reply reply = TryHandlers(request);
if (reply != null)
return reply;
}
catch (HandlerException exception)
{
Reply exceptionReply = new Reply(ReplyCode.BadRequest, ContentType.Plain, exception.Message);
return exceptionReply;
}
}
else
{
try
{
Reply reply = TryHandlers(request);
if (reply != null)
return reply;
}
catch (HandlerException exception)
{
Reply exceptionReply = new Reply(ReplyCode.BadRequest, ContentType.Plain, exception.Message);
return exceptionReply;
}
catch (Exception exception)
{
//Print the exception to the server console but don't leak any information to the client
string message = string.Format("An exception of type {0} occurred at {1}: {2}\n", exception.GetType().ToString(), exception.Source, exception.Message);
foreach (var trace in exception.StackTrace)
message += string.Format("{0}\n", trace);
Output.Write(message);
Reply exceptionReply = new Reply(ReplyCode.InternalServerError, ContentType.Plain, "Internal server error");
return exceptionReply;
}
}
if (CatchAll == null)
{
Reply invalidReply = new Reply(ReplyCode.NotFound, ContentType.Plain, "Invalid path");
return invalidReply;
}
else
return CatchAll.CatchAll(request);
}