Skip to content

Commit

Permalink
fix: log error if FrankenPHP is not properly started (#1314)
Browse files Browse the repository at this point in the history
Co-authored-by: Alliballibaba <[email protected]>
  • Loading branch information
AlliBalliBaba and Alliballibaba2 authored Jan 8, 2025
1 parent 2b7b3d1 commit 479ba0a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 479ba0a

Please sign in to comment.