Skip to content

Commit

Permalink
chore: keep the handler error instead of trying to hijack it as it br…
Browse files Browse the repository at this point in the history
…eaks 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. #83.
  • Loading branch information
jcchavezs committed Jul 8, 2023
1 parent b29f439 commit 29cc441
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions coraza.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

Expand Down

0 comments on commit 29cc441

Please sign in to comment.