From 29cc441a26f55ac49b685943486e7115d4c96f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Ch=C3=A1vez?= Date: Sat, 8 Jul 2023 06:40:14 +0200 Subject: [PATCH] chore: keep the handler error instead of trying to hijack it as it breaks the user experience. Currently when a later in the chain middleware returned an error with a certain status code, we attempted to wrap that error with an own error which lead to misleading behaviours e.g. https://github.com/corazawaf/coraza-caddy/issues/83. --- coraza.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/coraza.go b/coraza.go index a400f4d..4e36f91 100644 --- a/coraza.go +++ b/coraza.go @@ -128,10 +128,14 @@ func (m corazaModule) ServeHTTP(w http.ResponseWriter, r *http.Request, next cad // We continue with the other middlewares by catching the response if err := next.ServeHTTP(ww, r); err != nil { - return caddyhttp.HandlerError{ - StatusCode: 500, - ID: tx.ID(), - Err: err, + if hErr, ok := err.(caddyhttp.HandlerError); ok { + return hErr + } else { + return caddyhttp.HandlerError{ + StatusCode: 500, + ID: tx.ID(), + Err: err, + } } }