KestrunResponse.WriteErrorResponse method (1 of 2)

Writes an error response based on an exception. Chooses JSON/YAML/XML/plain-text based on override → Accept → default JSON.

public void WriteErrorResponse(Exception ex, int statusCode = 500, string? contentType = null, 
    bool includeStack = true)
parameter description
ex The exception to report.
statusCode The HTTP status code for the response.
contentType The MIME type of the response content.
includeStack Whether to include the stack trace in the response.

See Also


KestrunResponse.WriteErrorResponse method (2 of 2)

Writes an error response with a custom message. Chooses JSON/YAML/XML/plain-text based on override → Accept → default JSON.

public void WriteErrorResponse(string message, int statusCode = 500, string? contentType = null, 
    string? details = null)
parameter description
message The error message to include in the response.
statusCode The HTTP status code for the response.
contentType The MIME type of the response content.
details Optional details to include in the response.

See Also