diff --git a/caddy/caddy.go b/caddy/caddy.go index 8cbe7281f..19657578d 100644 --- a/caddy/caddy.go +++ b/caddy/caddy.go @@ -318,10 +318,14 @@ func (f FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ ca ) if err != nil { - return err + return caddyhttp.Error(http.StatusInternalServerError, err) + } + + if err = frankenphp.ServeHTTP(w, fr); err != nil { + return caddyhttp.Error(http.StatusInternalServerError, err) } - return frankenphp.ServeHTTP(w, fr) + return nil } // UnmarshalCaddyfile implements caddyfile.Unmarshaler. diff --git a/frankenphp.go b/frankenphp.go index 8193957fc..58516cacc 100644 --- a/frankenphp.go +++ b/frankenphp.go @@ -62,6 +62,7 @@ var ( MainThreadCreationError = errors.New("error creating the main thread") RequestContextCreationError = errors.New("error during request context creation") ScriptExecutionError = errors.New("error during PHP script execution") + NotRunningError = errors.New("FrankenPHP is not running. For proper configuration visit: https://frankenphp.dev/docs/config/#caddyfile-config") requestChan chan *http.Request isRunning bool @@ -454,6 +455,10 @@ func updateServerContext(thread *phpThread, request *http.Request, create bool, // ServeHTTP executes a PHP script according to the given context. func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error { + if !isRunning { + return NotRunningError + } + if !requestIsValid(request, responseWriter) { return nil }