From a5cfdf771c9a27f525734e24cc29f1b54bd9736c Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Sun, 23 Mar 2025 12:43:09 -0400 Subject: [PATCH] Added ResponseStatusException --- source/handy_http_primitives/response.d | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/handy_http_primitives/response.d b/source/handy_http_primitives/response.d index 8ab2691..7396c17 100644 --- a/source/handy_http_primitives/response.d +++ b/source/handy_http_primitives/response.d @@ -111,3 +111,25 @@ enum ContentTypes : string { TEXT_HTML = "text/html", TEXT_CSS = "text/css" } + +/** + * An exception that can be thrown while handling an HTTP request, to indicate + * that the server should return a specified response code, usually when you + * want to short-circuit due to an error. + */ +class HttpStatusException : Exception { + const StatusInfo status; + + this(StatusInfo status, string message, Throwable next) { + super(message, next); + this.status = status; + } + + this(StatusInfo status, string message) { + this(status, message, null); + } + + this(StatusInfo status) { + this(status, "An error occurred while processing the request.", null); + } +}