caddyhttp: Preserve original error (fix #5652)

This commit is contained in:
Matthew Holt 2023-07-25 09:41:56 -06:00
parent e041962b66
commit 18c309b5fa
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5

View file

@ -15,6 +15,7 @@
package caddyhttp package caddyhttp
import ( import (
"errors"
"fmt" "fmt"
weakrand "math/rand" weakrand "math/rand"
"path" "path"
@ -30,7 +31,8 @@ import (
// set will be populated. // set will be populated.
func Error(statusCode int, err error) HandlerError { func Error(statusCode int, err error) HandlerError {
const idLen = 9 const idLen = 9
if he, ok := err.(HandlerError); ok { var he HandlerError
if errors.As(err, &he) {
if he.ID == "" { if he.ID == "" {
he.ID = randString(idLen, true) he.ID = randString(idLen, true)
} }