Global Error Handling in FW
FW comes equipped with a GlobalExceptionHandler strictly mounted at the highest level of the Kernel HTTP Pipeline stack.
This guarantees that any unhandled generic Throwable, Custom Exception, or validation failure triggering internally is safely swallowed and formatted properly instead of crashing the Swoole worker process completely or leaking stack traces to untrusted clients.
Validation Errors
When using the FW API Compiler, DTO payloads aggressively validate themselves natively upon instantiation. If the payload is malformed or missing fields, FW throws a \Fw\Framework\Http\Exceptions\ValidationException.
The GlobalExceptionHandler traps this natively, reads the property error bag, and emits a structured HTTP 422 Unprocessable Entity Response mimicking this structure:
{
"status": "error",
"message": "Unprocessable Entity",
"errors": {
"email": ["Must be a valid email."],
"age": ["Must be at least 18."]
}
}Fatal Application Errors
By default, any unhandled fatal exception in your Handlers or Services will fall back to a HTTP 500 Internal Server Error, returning:
{
"status": "error",
"message": "Internal Server Error"
}Debug Mode
When APP_DEBUG=true is set in your local .env, the Exception trap disables strict masking and returns the full Message, the Exception Class, the exact File and Line, and a safe slice of the Stack Trace, ensuring rapid iterative development.