/// <summary>
        /// Format the response into something that the user understands.
        /// </summary>
        /// <param name="context">Context providing information for the error message generation</param>
        public void Format(ErrorFormatterContext context)
        {
            if (context.Response.Body == null)
                context.Response.Body = new MemoryStream();

            context.Response.ContentType = "text/html";
            var writer = new StreamWriter(context.Response.Body);
            writer.WriteLine("<html><head><title>Error 40</title></head><body>");
            writer.WriteLine("<h1>Opps. An error occurred.</h1>");
            writer.WriteLine("<p>" + context.Exception.Message + "</p>");
            writer.WriteLine("</body></html>");
        }
        /// <summary>
        /// Format the response into something that the user understands.
        /// </summary>
        /// <param name="context">Context providing information for the error message generation</param>
        public void Format(ErrorFormatterContext context)
        {
            if (context.Response.Body == null)
            {
                context.Response.Body = new MemoryStream();
            }

            context.Response.ContentType = "text/html";
            var writer = new StreamWriter(context.Response.Body);

            writer.WriteLine("<html><head><title>Error 40</title></head><body>");
            writer.WriteLine("<h1>Opps. An error occurred.</h1>");
            writer.WriteLine("<p>" + context.Exception.Message + "</p>");
            writer.WriteLine("</body></html>");
        }
 /// <summary>
 /// Invokes the <see cref="IErrorFormatter.Format"/> and guards against any exceptions that it might throw.
 /// </summary>
 /// <param name="response">Response to send back</param>
 /// <param name="msg">Request pipeline message</param>
 /// <param name="exception">Caught exception</param>
 protected virtual void FormatException(IResponse response, ReceivedHttpRequest msg, HttpException exception)
 {
     var formatterContext = new ErrorFormatterContext(exception, msg.HttpRequest, response);
     try
     {
         _formatter.Format(formatterContext);
     }
     catch (Exception err)
     {
         _logger.Error(
             string.Format("Formatter '{0}' failed to process request.", _formatter.GetType().FullName), err);
         var formatter = new SimpleErrorFormatter();
         formatter.Format(formatterContext);
     }
 }