Repository: caddyserver/caddy (language: go)

Issue:
Custom error message string is not output anywhere
The `error` directive accepts a message argument, but this string doesn't appear in any of the placeholders listed here https://caddyserver.com/docs/json/apps/http/#servers/errors/routes nor does it appear in the response body when a `handle_errors` template is not used (a zero size response body is returned).

If I configure something like `error "Forums are down for maintenance" 503` the placeholder values are

`http.error.status_code` "503"
`http.error.status_text` "Service Unavailable"
`http.error.message` ""
`http.error.trace` "caddyhttp.StaticError.ServeHTTP (staticerror.go:110)"
`http.error.id` "6persmrad"

Versions: 2.5.2 and fe5f5dfd6aa2f48e92897327c9c7d8c8583a3d72


Discussion / hints:
Hmm, that might be a documentation error (sadly, no pun intended). What is the value of the `{http.error}` placeholder for you?

But now that I look at things, I'm not sure which one was intended. Hmm. Yeah, lemme know what that is and we'll figure it out. (I haven't done much with this code since releasing v2, so I'm a bit rusty right now.)
`{id=gmcagza9n} caddyhttp.StaticError.ServeHTTP (staticerror.go:110): HTTP 503: Forums are down for maintenance`  
or  
`{id=bzgr3trhn} caddyhttp.StaticError.ServeHTTP (staticerror.go:110): HTTP 503:` (if no custom message is configured)

It would be nice if there was a placeholder that contained the custom message when set, and the generic message otherwise.
> If I configure something like `error "Forums are down for maintenance" 503` the placeholder values are
>
>`http.error.message` `"caddyhttp.StaticError.ServeHTTP"`

Weirdly enough, I can't replicate this with `respond "{http.error.message}"` 🤔 I don't think we actually ever set that placeholder! I just get a literal `{http.error.message}` written in the response. How did you test this?

https://github.com/caddyserver/caddy/blob/fe5f5dfd6aa2f48e92897327c9c7d8c8583a3d72/modules/caddyhttp/server.go#L517-L534

That said, I think we should add this line `repl.Set("http.error.message", handlerErr.Err.Error())` inside the `if` to populate that placeholder with the actual `HandlerError`'s message. Easy fix.

Fix patch:
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index f8cd612278a..73e14757b14 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -526,8 +526,9 @@ func (*HTTPErrorConfig) WithError(r *http.Request, err error) *http.Request {
 	if handlerErr, ok := err.(HandlerError); ok {
 		repl.Set("http.error.status_code", handlerErr.StatusCode)
 		repl.Set("http.error.status_text", http.StatusText(handlerErr.StatusCode))
-		repl.Set("http.error.trace", handlerErr.Trace)
 		repl.Set("http.error.id", handlerErr.ID)
+		repl.Set("http.error.trace", handlerErr.Trace)
+		repl.Set("http.error.message", handlerErr.Err.Error())
 	}
 
 	return r


Test patch: