- What is forkrefactor/apixception-bundle used for?
- It is a Symfony bundle that listens to kernel events and converts thrown exceptions into consistent JSON API error responses, so controllers do not need try/catch boilerplate. You configure status codes, error payload formats, and logging through attributes or package configuration. It is aimed at API-style projects that need predictable, debuggable error shapes.
- How do I install forkrefactor/apixception-bundle?
- Install it with Composer using composer require forkrefactor/apixception-bundle, then register the bundle in your Symfony application as required for your Symfony version. Check the repository README for the exact bundle registration and configuration file setup. Because it is a Symfony bundle, installation assumes a Symfony kernel, not a Laravel application.
- Does apixception-bundle work with Laravel?
- No, not natively. It is built around Symfony kernel events, while Laravel uses its own exception handler and middleware pipeline. You could reuse exception classes or rendering ideas, but you would need a Laravel adapter or middleware to produce the same JSON error responses. For Laravel-only projects, a Laravel-native package is usually a better fit.
- How do I configure status codes and error formats in apixception-bundle?
- The package supports configuring HTTP status codes, error response formats, and logging through attributes on exception classes or through package configuration. Use attributes when you want behavior defined close to the exception itself, and config when you want centralized control. Exact option names and examples are documented in the repository README.
- Which Symfony and PHP versions does apixception-bundle support?
- The repository README and composer.json are the authoritative source for supported Symfony versions and PHP constraints. Check the require section before installing, especially if you are on an older LTS or the newest major release. Because this is a smaller bundle, version support may lag behind the latest Symfony release.
- How do I test API error responses with apixception-bundle?
- Write functional tests that trigger each custom exception through a test HTTP request and assert the JSON status code and payload shape. In Symfony, use the KernelBrowser or your framework's HTTP test helpers, and cover both attribute-based and config-based exceptions. Also test logging behavior so production errors stay debuggable without leaking internals.
- Can apixception-bundle log exceptions while returning JSON errors?
- Yes, the package supports configuring logging alongside error rendering. The goal is to return a safe, consistent JSON response to clients while still recording useful exception details for debugging. Review your log levels and make sure sensitive data is not included in API responses.
- What are alternatives to apixception-bundle for API exception handling?
- In Symfony, many teams use built-in kernel exception listeners, FOSRestBundle-style exception handling, or custom EventSubscribers. In Laravel, the default exception handler plus custom render methods or API resources is common. Choose based on whether you want attribute-driven configuration or a more framework-native approach.
- Is apixception-bundle maintained and safe to use in production?
- Check the GitHub repository for recent commits, tagged releases, and open issues before using it in production. Since it is a smaller package, pin a version in composer.json and review the exception listener code for your use case. Also confirm compatibility with your Symfony and PHP versions.
- How does apixception-bundle compare to using Symfony's kernel.exception event directly?
- The bundle is essentially a structured wrapper around Symfony's kernel.exception event, adding configurable status codes, response formats, and logging. If you need only a few exception mappings, a small custom listener may be simpler. If you want consistent API errors across many exceptions without boilerplate, the bundle can save time.