src/packages/EmbedIO/ExceptionHandler.cs
/// <summary>
/// Sends a <c>500 Internal Server Error</c> response with a HTML payload
/// briefly describing the error, including contact information and/or a stack trace
/// if specified via the <see cref="ContactInformation"/> and <see cref="IncludeStackTraces"/>
/// properties, respectively.
/// </summary>
/// <param name="context">An <see cref="IHttpContext"/> interface representing the context of the request.</param>
/// <param name="exception">The unhandled exception.</param>
/// <returns>A <see cref="Task"/> representing the ongoing operation.</returns>
Sends a 500 Internal Server Error and
properties, respectively.
Sends a 500 Internal Server Error and properties respectively .
public static Task HtmlResponse(IHttpContext context, Exception exception)
            => context.SendStandardHtmlAsync(
                (int)HttpStatusCode.InternalServerError,
                text =>
                {
                    text.Write("<p>The server has encountered an error and was not able to process your request.</p>");
                    text.Write("<p>Please contact the server administrator");
                    if (!string.IsNullOrEmpty(ContactInformation))
                        text.Write(" ({0})", HttpUtility.HtmlEncode(ContactInformation));
                    text.Write(", informing them of the time this error occurred and the action(s) you performed that resulted in this error.</p>");
                    text.Write("<p>The following information may help them in finding out what happened and restoring full functionality.</p>");
                    text.Write(
                        "<p><strong>Exception type:</strong> {0}<p><strong>Message:</strong> {1}",
                        HttpUtility.HtmlEncode(exception.GetType().FullName ?? "<unknown>"),
                        HttpUtility.HtmlEncode(exception.Message));
                    if (IncludeStackTraces)
                    {
                        text.Write(
                            "</p><p><strong>Stack trace:</strong></p><br><pre>{0}</pre>",
                            HttpUtility.HtmlEncode(exception.StackTrace));
                    }
                });
public static Task HtmlResponse ( IHttpContext context , Exception exception ) => context . SendStandardHtmlAsync ( ( int ) HttpStatusCode . InternalServerError , text => { text . Write ( " " ) ; text . Write ( " " ) ; if ( ! string . IsNullOrEmpty ( ContactInformation ) ) text . Write ( " " , HttpUtility . HtmlEncode ( ContactInformation ) ) ; text . Write ( " " ) ; text . Write ( " " ) ; text . Write ( " " , HttpUtility . HtmlEncode ( exception . GetType ( ) . FullName ?? " " ) , HttpUtility . HtmlEncode ( exception . Message ) ) ; if ( IncludeStackTraces ) { text . Write ( " " , HttpUtility . HtmlEncode ( exception . StackTrace ) ) ; } } ) ;
Sends a 500 Internal Server Error and
properties, respectively.
Sends a 500 Internal Server Error and properties respectively .
A  representing the ongoing operation.
A representing the ongoing operation .
context
IHttpContext
An  interface representing the context of the request.
An interface representing the context of the request .
exception
Exception
The unhandled exception.
The unhandled exception .