- Can I use yiisoft/error-handler in Laravel instead of Laravel's built-in exception handler?
- You can, but it is not recommended as a replacement for Laravel's primary HTTP error path. Laravel relies on Illuminate\Foundation\Exceptions\Handler and its own middleware pipeline, not PSR-15, so the package will not plug in natively. The pragmatic approach is to keep Laravel's handler authoritative and consume the package's renderers and formatters behind a thin adapter, or restrict it to CLI and queue-worker paths. Budget for a PSR bridge, custom exception mapping, and response-format alignment before you see any value.
- Does yiisoft/error-handler auto-register a service provider in Laravel?
- No. The package ships no Laravel service provider, facade, or config file, so Composer discovery will register nothing. You must instantiate the handler and renderers yourself inside a service provider or bootstrap script. That also means you own the PSR-17 factory wiring, middleware registration, and any fallback logic.
- How do I install and configure yiisoft/error-handler with Composer?
- Install it with composer require yiisoft/error-handler, then pin the version and review the transitive dependency tree because the repository has low visible adoption and unclear provenance. Instantiate the handler or renderer in your own bootstrap code or service provider, since there is no artisan install command. Run a dependency audit and security scan before committing the lockfile change.
- Which PHP, PSR-7/PSR-15, and Laravel versions does yiisoft/error-handler support?
- The package is built around PSR-7 responses and PSR-15 middleware and targets modern PHP, but you should confirm the exact Composer constraints on Packagist before adoption. It does not declare Laravel support and is not tested against Laravel, so any Laravel version compatibility is something you have to prove yourself. Because Laravel requests and responses are not PSR-7, HTTP use requires a bridge such as symfony/psr-http-message-bridge plus PSR-17 factories.
- How do I return JSON error responses for a Laravel API using yiisoft/error-handler?
- The package can render structured JSON error payloads, but the result is a PSR-7 response that must be converted back into an Illuminate response. Do that inside an adapter called from your exception handler or a dedicated middleware, and define your error envelope and status-code contract up front. Compare its output against Laravel's native JSON rendering in shadow mode before exposing any route to real traffic.
- Can yiisoft/error-handler handle errors in CLI commands and queue workers?
- That is its strongest fit in a Laravel codebase, because console and job error paths sit outside Laravel's HTTP handler. A framework-independent handler can standardize error output, exit codes, and redaction across workers and standalone scripts. Build a thin wrapper that catches Throwable, delegates to the package, and falls back to Laravel's native handling if the adapter throws. Start with a time-boxed, non-production spike before touching anything critical.
- How do I switch between debug and production modes in yiisoft/error-handler?
- The handler supports debug and production modes, where debug renders verbose HTML or JSON with exception detail and production returns generic output. Drive the flag from an environment variable such as APP_DEBUG inside your adapter so behavior matches the rest of the application. Never enable debug in production, and add a test that asserts sensitive values are absent from the production payload.
- How do I integrate yiisoft/error-handler logging with Laravel's log stack and observability tooling?
- The package supports logging but will not use Laravel's logger automatically, so you need to inject a PSR-3 logger that Laravel's logging stack backs. Keep Laravel's own exception reporting active as well, otherwise existing channels, metrics, and Sentry or alerting integrations go blind. Decide explicitly which layer owns reporting and deduplicate to avoid double-logged exceptions.
- Is yiisoft/error-handler safe for production, or can it leak stack traces and sensitive data?
- Production mode suppresses detailed traces, but the package still renders error content and its security-review status is unknown. Test redaction of credentials, SQL fragments, request bodies, and environment values in every output format you enable. Keep Laravel's native handler as a fallback, pin versions, and complete a dependency audit before adding the package to a production lockfile.
- Is yiisoft/error-handler actively maintained, and what are the alternatives for Laravel?
- Adoption signals are weak: roughly 22 stars, Yii-centric documentation, unknown repository provenance, and limited visibility into release cadence or maintainer depth. For Laravel-only projects, the built-in exception handler with its HTML and JSON rendering, optionally paired with a package like Spatie Ignition, is the lower-risk choice. Consider yiisoft/error-handler only when you genuinely need one shared, framework-independent error pipeline across Yii, standalone PHP services, and legacy systems.